Hello, im still having this issue at Xcode beta 5, and none of the above workarounds does work either.
My #Preview Code:
#Preview {
MainActor.assumeIsolated {
let modelContainer: ModelContainer = ModelContainer.preview()
return TaskListView()
.modelContainer(modelContainer)
}
}
My ModelContainer.preview() Code:
#if DEBUG
@MainActor
extension ModelContainer {
static func preview() -> ModelContainer {
do {
let modelContainer = try ModelContainer(for: [TaskListModel.self], ModelConfiguration(inMemory: true))
for element in [TaskListModel].preview() {
modelContainer.mainContext.insert(element)
}
return modelContainer
} catch let error {
fatalError("[ModelContainer] static preview(taskLists:): \(error.localizedDescription)")
}
}
}
#endif
Post
Replies
Boosts
Views
Activity
I think we can use modelContainer.mainContext.autosaveEnabled = ... for autosave. However it is not tested if this actually has an effect, only if it complies, as Previews currently crash for me.