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.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: