Hi. I recently incorporated the new NSManagedDocument into my core data library-style app, and now I'm trying to implement iCloud. I enabled entitlements, created an iCloud enabled provisioning profile, started observing NSMetadataQueryDidFinishGatheringNotification and NSMetadataQueryDidUpdateNotification with the passed object being my iCloud query, and set the persistent store options (NSPersistentStoreUbiquitousContentURLKey and NSPersistentStoreUbiquitousContentNameKey). Something odd to note is that I must put a call to the method that sets my persistent store options in the setter of the UIManagedDocument in order for my app to appear in iCloud. The app won't show up in iCloud if I put the call to the method that sets the options in viewdidload or viewwillappear.
Here is the setter for my UIManagedDocument:
Code:
-(void)coreDataDatabase_ManagedDocument:(UIManagedDocument *)coreDataDatabase_ManagedDocument
{
[[NSFileManager defaultManager] fileExistsAtPath:[self.coreDataDatabase_ManagedDocument.fileURL path]];
if (_coreDataDatabase_ManagedDocument != coreDataDatabase_ManagedDocument) {
_coreDataDatabase_ManagedDocument = coreDataDatabase_ManagedDocument;
[self setPersistentStoreOptions];
[self useDocument]; //Open the document and setup the fetched results controller upon completion
}
}
Here is the callback method for both the notifications:
Code:
-(void)processCloudQueryResults:(NSNotification *)notification
{
[self.iCloudQuery disableUpdates]; //Stop updates so we can't receive any while we're updating everything
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.coreDataDatabase_ManagedDocument.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
});
[self.iCloudQuery enableUpdates]; //re-enable updates
}
Whenever I run this on one device everything works as expected. However when I load it up on the second device, it works fine on the second device, but it then crashes on the first device with the error
Quote:
|
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (3) beyond bounds (3)'
|
Any ideas?