Post

Replies

Boosts

Views

Activity

Reply to SwiftData Fatal error: failed to find a currently active container
This happened to me on iOS 17.5 (it works fine on iOS 18). What I did was simply initialize the ModelContainer in the @main struct. The odd thing that I don’t use this contaner reference anywhere, but it does fix the crash issue let container: ModelContainer? init() { do { let config = ModelConfiguration(isStoredInMemoryOnly: true) container = try ModelContainer(for: ModelName.self, configurations: config) } catch { print("Failed to initialize ModelContainer: \(error)") container = nil } } usage: WindowGroup { } .modelContainer(for: ModelName.self) // please note that it should be the @Model name, not a ModelContainer.
Jan ’25