Two persistent stores for one managed object context - possible?

这一生的挚爱 提交于 2019-12-01 17:41:13

问题


I have a fairly complex data model with approximately 10 entities. Some need to be stored to disk and others just need to be available in memory when the application is running. Is it possible to achieve this using two persistent stores for the same managed object context, or should I separate my data models accordingly?


回答1:


Yes, your NSManagedObjectContext uses a NSPersistentStoreCoordinator to determine which store a particular model should use. By setting the persistent store coordinator of your managed object context you can define a custom mapping which uses multiple persistent stores of different types.

http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdBasics.html#//apple_ref/doc/uid/TP40001650-SW4




回答2:


You may use configurations as TechZen mentioned:

  1. Create Configurations in managed object model editor (.xcdatamodel file);
  2. In code add several persistent stores to persistent store coordinator, providing appropriate configuration name.

For details check my other answer here.



来源:https://stackoverflow.com/questions/5398927/two-persistent-stores-for-one-managed-object-context-possible

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