Frage

As a regular safety background task in my app, I have to save my NSManagedObjectContext with the SaveAs... method called migratePersistentStore:toURL:options:withType:error:. However, this method removes the storefrom the coordinator and adds the new store. This is fatal because my complete UI is based on objects loaded from the old store. Reloading the UI is no option because the user may be working deep within the UI and currently editing objects loaded from the old store.

My idea is to bring up a second stack of coordinator, moc and so on and let this duplicate perform the migration. Can a NSPersistentStore be safely opened (readOnly) by a second coordinator? My guess is not. I don't understand why Apple didn't add an option to keep the original store after the migration.

War es hilfreich?

Lösung

If your store is a SQLite store then yes you can open as many NSPersistentStoreCoordinator instances as you want. If you are not using a SQLite store then I would not recommend it.

However, if you are doing a back-up, is there a reason you are not copying the file using NSFileManager instead? Should be significantly faster than a migration. Fast enough that you could safely lock the store during the copy.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top