Can two managed object context share one single persistent store coordinator?

爷,独闯天下 提交于 2020-01-04 02:18:09

问题


Example: I have one persistent store coordinator which uses one single persistent store.

Now there are two managed object contexts, and both want to use the same persistent store. Could both simply use the same persistent store coordinator, or would I have to create two instances of NSPersistentStoreCoordinator? And if I had to, then: Would I also have to create two NSPersistentStore instances?


回答1:


The Core Data on iPhone article on ADC gives a good introduction to this topic:

In any application, you might have multiple managed object contexts. You might want to maintain discrete sets of managed objects and edits to those objects; or you might want to perform a background operation using one context while allowing the user to interact with objects in another. Each of these would be connected to the same coordinator.

A Persistent Store Coordinator is designed to handle multiple contexts



来源:https://stackoverflow.com/questions/2989015/can-two-managed-object-context-share-one-single-persistent-store-coordinator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!