Blank white screen with default Xcode 12 Core Data project

Viewed 301

When starting a brand new out-of-the-box SwiftUI project with Core Data on Xcode 12.1.1, Mac OS X Catalina 10.15.17, the project just builds to a white screen - whether on the simulator or on my device.

The Preview also does not show the "Add Item" Button or EditButton that are supposed to be there in the view.

I have literally no idea why, and wonder if anyone has a solution to this? There are reports of this for much older versions of Xcode which are of course not relevant to Xcode 12.

1 Answers

It needs to add some more code - wrap into NavigationView and separate placements for buttons (which you can modify to your needs, of course)

Demo prepared with Xcode 12.1 / iOS 14.1

var body: some View {
    NavigationView {
        List {
            ForEach(items) { item in
                Text("Item at \(item.timestamp!, formatter: itemFormatter)")
            }
            .onDelete(perform: deleteItems)
        }
        .toolbar {
            #if os(iOS)
            ToolbarItem {
                EditButton()
            }
            #endif
            ToolbarItem(placement: .bottomBar) {
                Button(action: addItem) {
                    Label("Add Item", systemImage: "plus")
                }
            }
        }
    }
}
Related