Multiple databases with MagicalRecord or sync only part of the database for iCloud

I am currently syncing my entire master data store with iCloud so that the same data is available on all iOS devices of users. All of this is configured using MagicalRecord by doing the following:

[MagicalRecord setupCoreDataStackWithiCloudContainer:@"xxxxxxx.com.mydomain.MyAppName" localStoreNamed:@"MyAppName"]; 

However, I would like to store some device-specific objects in the database. It is mainly used for caching information received from the Internet, and I do not want this to take up space in the iCloud user account.

I believe that there would be two ways to do this:

  • Choose which database tables should be synchronized and ignore tables used for device-specific objects.
  • Ask MagicalRecord to manage multiple databases and store objects that need to be synchronized in one database and another device in another.

I do not know if any of these two methods is possible or which will be easiest to support and / or implement.

Does anyone know if this is possible and how it can be done? Sample code is welcome.


UPDATE

I try to follow the approach suggested by casademora below , but at the same time both of my stores end up with beign synchronized with iCloud. I added the following to 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 added two data models to the project. One of them is called MyAppName_iCloud.xcdatamodeld and one named MyAppName.xcdatamodeld.

I would like the MyAppName repository to sync with iCloud.

+3
source share
1 answer

MagicalRecord is just a collection of useful helper methods that make working with CoreData simple. MagicalRecord is not a wrapper or replacement for CoreData. This is the key to understanding that no matter what CoreData can do, MagicalRecord can do it. So, if CoreData can handle multiple persistent stores, MagicalRecord can as well. The only trick is to find a suitable helper method that suits your needs. In this case, this method is in the NSPsistentStoreCoordinator. Take a look at the -addSqliteStoreNamed: method. This will do what you need, without all the additional parameters of the usual addPersistentStore: method (which is actually used under the covers)

+2
source

All Articles