I am currently syncing my entire Core Data store to iCloud so that the same data is available on all of the users iOS devices. This is all set up using MagicalRecord by doing this:
[MagicalRecord setupCoreDataStackWithiCloudContainer:@"xxxxxxx.com.mydomain.MyAppName" localStoreNamed:@"MyAppName"];
However, I would like to store some device specific entities in the database. It’s basically used for caching information retrieved from the web and I don’t want this to take up space on the users iCloud account.
I believe there would be two ways to do this:
- Choose which tables of a database should be synchronized and ignore the tables used for device specific entities.
- Have MagicalRecord manage multiple databases and store the entities which should be synchronized in one database and the device specific in the other.
I don’t know if any of those two ways are possible or which would be the most simple to maintain and/or implement.
Does anyone know if this is possible and how it can be done? A code example would be greatly appreciated.
UPDATE
I am trying to follow the approach proposed by casademora in the answer below but when doing so both of my stores end up beign synced to iCloud. I have added the following in application:didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[MagicalRecord setupCoreDataStackWithiCloudContainer:@"xxxxxxxxx.com.mydomain.MyAppName" localStoreNamed:@"MyAppName_iCloud"];
[[NSPersistentStoreCoordinator coordinatorWithInMemoryStore] addSqliteStoreNamed:@"MyAppName" withOptions:nil];
// Override point for customization after application launch.
return YES;
}
I have added two data models to the project. One named MyAppName_iCloud.xcdatamodeld and one named MyAppName.xcdatamodeld.
I would like to avoid that the MyAppName store is synced to iCloud.
MagicalRecord is merely a collection of useful helper methods that make CoreData easier to deal with. MagicalRecord is not a wrapper or a replacement for CoreData. This is key to understand that whatever CoreData can do, MagicalRecord can do. So, if CoreData can handle multiple persistent stores, MagicalRecord can as well. The only trick is to find the proper helper method that fits your needs. In this case, that method is in NSPersistentStoreCoordinator. Take a look at the -addSqliteStoreNamed: method. This will do what you need, without all the extra parameters of the regular addPersistentStore: method (which is actually used under the covers anyhow)