Sample project not working?

You can use the new project assistant in Xcode 12 (12A8189n) to create a iOS app project using SwiftUI, a SwiftUI App life cycle and Core Data. The resulting app seems fully functional on its back end, and SwiftUI previews work in the IDE… but when I run it to either simulator or device, it's just an empty white canvas. There's no items in the list (which I wouldn't necessarily expect), no Add button and no Edit button.

I'm sure this is because this is unfinished and just a beta, but is there something I can do to make the project work? I'm not looking to ship something right now, but being able to play with these tools would be great.
Answered by DanOLeary in 632184022
I believe the problem is a bug in the .toolbar where items will not show up. If you replace Apple's default code and use .navigationBarItems (instead of .toolbar) you'll be able to see the buttons so you can add items to the CoreData list. Replace the default View body code with this and it should work for you.

Code Block
var body: some View {
NavigationView {
List {
ForEach(items) { item in
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
}
.onDelete(perform: deleteItems)
}
.navigationBarItems(leading: EditButton(),
trailing: Button(action: addItem, label: { Label("Add Item", systemImage: "plus") })
)
}
}


Accepted Answer
I believe the problem is a bug in the .toolbar where items will not show up. If you replace Apple's default code and use .navigationBarItems (instead of .toolbar) you'll be able to see the buttons so you can add items to the CoreData list. Replace the default View body code with this and it should work for you.

Code Block
var body: some View {
NavigationView {
List {
ForEach(items) { item in
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
}
.onDelete(perform: deleteItems)
}
.navigationBarItems(leading: EditButton(),
trailing: Button(action: addItem, label: { Label("Add Item", systemImage: "plus") })
)
}
}


well doesn't seems to work in Xcode 12.5...

That's what the template holds

Code Block
.toolbar {
            #if os(iOS)
            EditButton()
            #endif
            Button(action: addItem) {
                Label("Add Item", systemImage: "plus")
            }
        }


my bad I didn't see I had to change also the header and put everything in a navigationController
Sample project not working?
 
 
Q