Post

Replies

Boosts

Views

Activity

Reply to SwiftData ModelContainer can not be created in iOS 17.4 Beta
Thanks @mikrasya for documenting this. I have the same problem, but already have inverses set. Removing inverses didn't help either. (I've read that inverses aren't necessary when using iCloud, that they are automatically inferred). 🤷🏼‍♂️ I sent in a question to Developer Tech Support, and will repeat any solution here for you and the other five who've marked your posting with "Same Here".
Mar ’24
Reply to EnvironmentObject Causes SwiftUI App to Crash When Launched in the Background
Same here. Starting with iOS 17.4, my app waking in the background would crash when accessing an invalid modelContext environment variable. Even moving the app into the background with recent SwiftData changes (especially changes to Relationships) caused the same crash. My guess is that an autoSave is triggered? Easier to reproduce on iPad. My workaround, based on the helpful discussion above.... Create a globally accessible modelContext and modelContainer. In my case I created a singleton "DataCenter" object created in the first line of the app's init. Remove ALL @Environment(.modelContext) private var modelContext from your project Add the modelContainer modifier to the WindowGroup, in my case WindowGroup{...}.modelContainer(DataCenter.shared.container) Use that global context directly when needed, such as DataCenter.shared.context.insert(...) Half measures didn't work for me, such as just removing the modelContext environment variable from the root view. Had to **** it entirely in the project.
May ’24