Created
October 9, 2012 04:41
-
-
Save blackgold9/3856657 to your computer and use it in GitHub Desktop.
Alternate contextWillSave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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