Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two persistent stores for one managed object context - possible?

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?

like image 687
ruipacheco Avatar asked Mar 22 '11 23:03

ruipacheco


People also ask

Can we have more than one managed object context?

Most apps need just a single managed object context. The default configuration in most Core Data apps is a single managed object context associated with the main queue. Multiple managed object contexts make your apps harder to debug; it's not something you'd use in every app, in every situation.

Can persistent store coordinator have multiple persistent store?

An app typically does not interact with a persistent store coordinator beyond just instantiating it when setting up the Core Data environment. The persistent store coordinator can manage communication with more than one persistent store so that the details of how the data are stored is hidden.

Will you ever pass managed object from one context to another context?

You cannot pass NSManagedObjects between multiple contexts, but you can pass NSManagedObjectIDs and use them to query the appropriate context for the object represented by that ID.

When managed object context saves its changes where does it push changes next?

When one of the managed object contexts is saved, its changes are pushed through the persistent store coordinator to the persistent store.


1 Answers

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

like image 132
Jonah Avatar answered Nov 03 '22 14:11

Jonah