I've got an iOS app with SwiftData in production now. Not a huge amount of users, but decent amount. I'm using SwiftData to persist local "notes" or "logs" about data the user records while using the app for their own reference. So the data only lives on their device.
So I recently made some changes to the models and it required using new schema versions. So I set up a SchemaMigrationPlan and tested it out locally and everything was working well. At the app root, I have this...
init() {
do {
container = try ModelContainer(
for: Foo.self, Bar.self,
migrationPlan: MyAppSchemaMigration.self
)
} catch {
fatalError("Error migrating --- \(error.localizedDescription)")
}
}
I've since received 10 crash reports over the past 2 weeks show up in Xcode Organizer from this fatalError
, all from the same device. I'm unsure how to approach resolving this though, since the user hasn't reached out, so I can't provide direct support. This is definitely a tiny minority of people experiencing this crash, at least that are being reported. but it still makes me wonder if I could handle this better? And 10 crashes implies that relaunching the app isn't helping this person. What's the appropriate way to recover from this type of error? fatalError
is so user unfriendly, but what else can you do in this situation? Would it be possible to somehow manually migrate? I can't just throw the data out and regenerate it because the data only lives on their device.