Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly removing existing on-save notificaitons before replacing the…

… default or root contexts
  • Loading branch information...
commit 343b027e254636fc3336064bf8c92675e4ca8317 1 parent 31b2e54
@blackgold9 blackgold9 authored
View
16 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.m
@@ -52,6 +52,11 @@ + (NSManagedObjectContext *) MR_defaultContext
+ (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
{
+ if (defaultManagedObjectContext_)
+ {
+ [[NSNotificationCenter defaultCenter] removeObserver:defaultManagedObjectContext_];
+ }
+
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
if (iCloudSetupNotificationObserver) {
[[NSNotificationCenter defaultCenter] removeObserver:iCloudSetupNotificationObserver];
@@ -88,6 +93,11 @@ + (NSManagedObjectContext *) MR_rootSavingContext;
+ (void) MR_setRootSavingContext:(NSManagedObjectContext *)context;
{
+ if (rootSavingContext)
+ {
+ [[NSNotificationCenter defaultCenter] removeObserver:rootSavingContext];
+ }
+
rootSavingContext = context;
[context MR_obtainPermanentIDsBeforeSaving];
[rootSavingContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
@@ -174,8 +184,10 @@ - (void)contextWillSave:(NSNotification *)notification
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]);
NSError *error = nil;
- [context obtainPermanentIDsForObjects:insertedObjects error:&error];
- [MagicalRecord handleErrors:error];
+ BOOL success = [context obtainPermanentIDsForObjects:insertedObjects error:&error];
+ if (!success && error) {
+ [MagicalRecord handleErrors:error];
+ }
}
}

0 comments on commit 343b027

Please sign in to comment.
Something went wrong with that request. Please try again.