0

作为我应用程序中的常规安全后台任务,我必须NSManagedObjectContext使用名为migratePersistentStore:toURL:options:withType:error:. 但是,此方法会从协调器中删除存储并添加新存储。这是致命的,因为我的完整 UI 是基于从旧商店加载的对象。重新加载 UI 不是选项,因为用户可能在 UI 深处工作并且当前正在编辑从旧商店加载的对象。

我的想法是调出第二组协调器、moc 等,让这个副本执行迁移。第二个协调员可以NSPersistentStore安全地打开(只读)吗?我的猜测不是。我不明白为什么 Apple 在迁移后没有添加保留原始商店的选项。

4

1 回答 1

0

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.

于 2014-02-04T17:36:04.873 回答