SwiftData M1L2 and M1L3

I’m running through the demo app, and I’ve coded everything per the tutorial, but my preview crashes when I hit the “Add” button in preview. When I run the app, the screen is blank (white). I opened the project from the Dropbox provided in the tutorial and it’s doing the same thing.


What version of Xcode do you have and what code do you have in your #Preview closure for ContentView apart from just ContentView()?

You need to inject the modelContainer into the Preview like this:

#Preview {
        .modelContainer(for: DataItem.self)
1 Like

I’m running Xcode 15.0.1 (15A507).

injecting the modelContainer into the Preview worked! Thank you so much.

1 Like