Post

Replies

Boosts

Views

Activity

Reply to SwiftUI SwiftData Previews not working as expected
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
Jul ’23