Skip to content

Instantly share code, notes, and snippets.

@tritchey
Created July 27, 2014 20:37
Show Gist options
  • Save tritchey/ad512c782e69265ffef3 to your computer and use it in GitHub Desktop.
Save tritchey/ad512c782e69265ffef3 to your computer and use it in GitHub Desktop.
Background merge
- (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