Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

iCloud Core Data Crash?

WhitehkWhitehk Posts: 119Registered Users
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:

 -(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:

-(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
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (3) beyond bounds (3)'
Any ideas?
Sign In or Register to comment.