I have an app in the app store which is working fine. Some users reported that they have app crashing when they are using iOS 17.4 beta. I could recreate the issue and it is happening when ModelContainer is crerated. This code..
do {
let configuration = ModelConfiguration(for: MyTodo.self, isStoredInMemoryOnly: false)
modelContainer = try ModelContainer(for: MyTodo.self, configurations: configuration)
} catch {
fatalError("Failed to load model container.\(error)")
}
is throwing this error message:
Fatal error: Failed to load model container.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
It seems for whatever reason inverse relationship needs to be explicitly defined. Change from this:
@Relationship(deleteRule: .cascade) var tasks: [MyTask]? = []
to
@Relationship(deleteRule: .cascade, inverse: \MyTask.todo) var tasks: [MyTask]? = []
has solved the crash issue. Works both in iOS 17.3 and 17.4.