Question

My App uses two UITableViewController with their respective NSFetchedResultController to display its data. They are kept inside a UITabBarController. The user can enable iCloud in the App settings bundle.

When the app starts with iCloud disabled both the tables are populated with data and work flawlessly.

The app shows immediately the data of the first controller to the user.

If the user goes into the app settings and turns on the "use iCloud switch", when the app enters foreground he is asked if he really wants to merge data with iCloud. If he answers YES then I:

1) Reset child and parent context and I remove the existing store from the coordinator.

2) I reload the store in another context and I migrate it with the iCloud options using migratePersistentStore:toURL:options:withType:error

3) I remove the old local files

4) I add the new iCloud enabled persistent store to the coordinator.

Everything is fine up to this point but after migration if I tap to the second tab, the UITableViewController frc (that was working perfectly before migration) tries to refresh the data and I get this error:

object's persistent store is not reachable from this nsmanagedobjectcontext's coordinator

When this appens, the iCloud enabled persistent stores appears inside the coordinator PersistentStores array! It is correctly the only one.

If I close the app and I restart it everything works fine, the new iCloud enabled database is loaded as the app store and there are no problems displaying objects.

How can I fix this problem?

Was it helpful?

Solution

As suggested the problem was I kept around managed objects from the old store. I fixed posting a notification when the migration completes then I set to nil the all the NSFetchedResultsController, I recreate them and I ask them to perform their request. Now everything works as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top