I'm working on a small iPhone logging app and I want to keep a database of location data separate from the users logged data.
I have several reasons for separating the two including
1) I'll probably push periodic location data updates with app updates and I don't want to risk making a cockup and affecting the users data.
2) the location data will probably dwarf the user data so synching and backing up the users file will happen quicker if the two are separate.
So given I intend to have two persistent stores are there advantages or disadvantages in terms of performance and coding complexity to having one context with two persistent stores in it over 2 separate contexts each with their own persistent store?
Any thought on this would be greatly appreciated - i'm a bit of a n00b when it comes to this stuff - thanks in advance
Simon .
I have implemented a similar thing in my app, I load data from 2 databases because I want to push updates to a certain set of data.
The way I have done it is using 1 object model, 1 managed object context but 2 persistent stores, each one loading a different sqlite file. To do this I created 2 configurations in data model file then dragged the appropriate entities into each configuration. Then when you create the persistent stores do it like this:
[__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"Configuration1" URL:store1URL options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil] error:&error];
[__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"Configuration2" URL:store2URL options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil] error:&error];
The only problem I have found with this so far is you cant have relationships between stores. This answer shows how to use a fetched property to replicate a relationship.
Hope this helps.