Thank you very much for your answer Ziqiao!
I have a better understanding of the logic behind the error.
And yes I do have widgets! So this seems to be the best lead. I have added additional logging, hoping to confirm this theory. But it will take time and effort to be 100% sure.
Meanwhile, let's say this is really the culprit, how do you officially approach this issue?
I can think of these 2 potential solutions:
Is there a way to "detect and wait" for a migration to be done? So that when the widget (or the main app) initializes the shared CoreData stack, I first check if a migration is ongoing and retry to open later?
Do you recommend avoiding sharing the same CoreData stack between the main app and the widget? So I should create a separate CoreData file exclusive to widgets?
I can even think of a third solution which is close to manually doing solution 1. I create my own set of flags lastMigrationVersion and lastMigrationDate.
If I see that a stack (let's say the main app one) did trigger a lightweight migration, I can check if enough time was given for the migration before attempting to open the stack from elsewhere (let's say from the widget). But it means hardcoding a static delay of... let's imagine 1.5 second before opening a potentially migrating CoreData stack. I have no idea how long a migration can last unfortunately but I take that 1 second should be enough in the majority of cases? It's not a stable solution...
What do you recommend?
Post
Replies
Boosts
Views
Activity
I would also like to add that I believe that for users facing this error, a simple restart of the app fixes the problem. I can't confirm that it is 100% the case for all of them, but it seems like it.
I had a report where a user who would use the app daily (always up to date) opened the app and suddenly got this error, killed the app, and it went away at the next app opening.
The message ("The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store.") feels like a moot reason. If it was really incompatible, it shouldn't be able to auto-fix itself at next app launch.
I also believe that this thread shares the same root issue although we have different schema updates: https://developer.apple.com/forums/thread/748543
They added Fetch Index Elements, I added parameters.
If a CoreData team member was able to shred some light... Or at least give a direction.
Same issue here on iOS 17.5.1
Can we hope for an iOS 18 fix?