1

I'm trying to integrate iCloud in my old project but at the same time trying to update the database with MagicalRecord. iCloud works when I'm not using a custom .sqlite file name, but not with a custom one. Here, there is some code that explains better what I mean.

// Load model. Don't use the standard 'merged model' of Magical Record, because that would include
// the Ensembles model. Don't want to merge models.
NSManagedObjectModel *model = [NSManagedObjectModel MR_newManagedObjectModelNamed:@"Polyglott.momd"];
[NSManagedObjectModel MR_setDefaultManagedObjectModel:model];

// Setup Core Data Stack
[MagicalRecord setShouldAutoCreateManagedObjectModel:NO];

// This is the custom file name
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"PolyglottModel"];
// Here is the default one
// [MagicalRecord setupAutoMigratingCoreDataStack];

// Setup Ensemble

// Here, I'm not sure which one is the right way
NSURL *url = [NSPersistentStore MR_urlForStoreName:@"PolyglottModel.sqlite"];
// NSURL *url = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Polyglott" withExtension:@"momd"];
self.cloudFileSystem = [[CDEICloudFileSystem alloc] initWithUbiquityContainerIdentifier:@"iCloud.de.thm.polyglott"];
self.ensemble = [[CDEPersistentStoreEnsemble alloc] initWithEnsembleIdentifier:@"PolyglottMR"
                                                            persistentStoreURL:url
                                                         managedObjectModelURL:modelURL
                                                               cloudFileSystem:self.cloudFileSystem];
self.ensemble.delegate = self;

// Listen for local saves, and trigger merges
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localSaveOccurred:) name:CDEMonitoredManagedObjectContextDidSaveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cloudDataDidDownload:) name:CDEICloudFileSystemDidDownloadFilesNotification object:nil];

[self syncWithCompletion:nil];

leechPersistentStoreWithCompletion nor mergeWithCompletion give me any error but when I request the database, there is no data.

Any idea or example? Thank you so much in advance.

1 Answers1

0

I assume you have looked at the MagicalRecord sample code in Ensembles.

I'm not sure exactly what is wrong, but I am going to guess that you are not passing the right name to MR_urlForStoreName:. You probably should leave off the extension or something like that. It should be easy to see by setting a breakpoint and printing the URL to see if it is correct.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23
  • You are right, i was following the sample code. I tried both names, with and without .sqlite. Actually, checking the path i've seen it without the extension. Anyway, it doesn't work either. Finally i've decided to copy the store from the custom file to the default one just for the update and use the default one from there on. It's a bit tricky but fast solution. Thanks! – Fernando Silva May 19 '16 at 12:37