Skip to content

Instantly share code, notes, and snippets.

@blackgold9
Created October 9, 2012 04:41
Show Gist options
  • Save blackgold9/3856657 to your computer and use it in GitHub Desktop.
Save blackgold9/3856657 to your computer and use it in GitHub Desktop.
Alternate contextWillSave
- (void)contextWillSave:(NSNotification *)notification
{
NSManagedObjectContext *context = (NSManagedObjectContext *)notification.object;
if (context.insertedObjects.count > 0) {
NSArray *insertedObjects = [[context insertedObjects] allObjects];
MRLog(@"Context %@ is about to save. Obtaining permanent IDs for new %lu inserted objects", [context MR_description], (unsigned long)[insertedObjects count]);
__autoreleasing NSError *error = nil;
BOOL success = [context obtainPermanentIDsForObjects:insertedObjects error:&error];
if (!success && error) {
[MagicalRecord handleErrors:error];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment