Post

Replies

Boosts

Views

Activity

Reply to it will crash, when i Use SwiftData in Preview
Creating an instance of the model class TestItemTotal without a model context (from a container) present will crash the preview. To fix this you can change your preview code to: #Preview { do { let config = ModelConfiguration(isStoredInMemoryOnly: true) // Store the container in memory since we don't actually want to save the preview data let container = try ModelContainer(for: TestItemTotal.self, configurations: config) var item = TestItemTotal("james qq") return TestItemTotalDetail(currentItem: item) .modelContainer(container) } catch { return Text("Failed to create preview: \(error.localizedDescription)") } }
Feb ’24