Created
July 27, 2014 20:37
-
-
Save tritchey/ad512c782e69265ffef3 to your computer and use it in GitHub Desktop.
Background merge
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)backgroundContextDidSaveNotification:(NSNotification*)notification | |
{ | |
for (NSManagedObject *object in notification.userInfo[NSDeletedObjectsKey]) { | |
NSLog(@"deleted: %@", object.entity.name); | |
} | |
// the background moc saved - merge changes | |
NSManagedObjectContext *context = [self managedObjectContext]; | |
void (^mergeChanges) (void) = ^ { | |
[context mergeChangesFromContextDidSaveNotification:notification]; | |
}; | |
if ([NSThread isMainThread]) { | |
mergeChanges(); | |
} else { | |
dispatch_sync(dispatch_get_main_queue(), mergeChanges); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment