re: the SwiftData session "Create an app with SwifData" (https://developer.apple.com/videos/play/wwdc2023/10154)
I corrected the @MainActor issue, but it seems to only work with the main ContentView and not other views.
I get the following error for TripListItem for example :
failed to find a currently active container for Trip
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)
}
}
}