Skip to content

Instantly share code, notes, and snippets.

@tritchey
Created July 27, 2014 20:37

Revisions

  1. Tim Ritchey created this gist Jul 27, 2014.
    16 changes: 16 additions & 0 deletions vigilCoreDatabase.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    - (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);
    }
    }