Two persistent stores for one managed object conte

2019-02-22 09:41发布

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?

2条回答
不美不萌又怎样
2楼-- · 2019-02-22 10:32

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.

查看更多
Deceive 欺骗
3楼-- · 2019-02-22 10:33

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

查看更多
登录 后发表回答