I am creating multiple persistent store in my application, but I am using only one persistent store coordinator and managed object model. Now my question is when I call save method on managed object context, which persistent store it will use to save the object. So I want to specify the persistent store to be used to save the object. Same while fetching the objects from database, I want to ensure that my fetch query should be executed on a particular store so that I get objects from that store only. Any help?
Share
Fetching should not be an issue. The fetch request can be modified to search particular stores using the setAffectedStores: method on an NSFetchRequest.
When you’re creating an object, you can assign the entity to a particular store using the assignObject:toPersisentStore: method on NSManagedObjectContext.
As to your question, there isn’t really a default mechanism that I am aware of, and it may be that you simply need to set the affected stores to all of your stores:
[request setAffectedStores:[NSArray arrayWithObjects:firstStore,secondStore,thirdStore, nil]];To be sure that you’re looking in all the right places.