Post

Replies

Boosts

Views

Activity

Reply to SwiftUI SwiftData Previews not working as expected
I was still running into this and similar errors getting SwiftUI views with SwiftData to preview successfully. It seems to me that you need to instantiate the container before you can reference the SwiftData objects in the container. I was finally able to solve it with the following: #Preview { MainActor.assumeIsolated { let container = PreviewSampleData.container return List { TripListItem(trip: Trip.preview) .modelContainer(container) } } }
Jun ’23