Skip to content

Instantly share code, notes, and snippets.

@zigphroid
Created November 28, 2011 03:29
Show Gist options
  • Save zigphroid/1398971 to your computer and use it in GitHub Desktop.
Save zigphroid/1398971 to your computer and use it in GitHub Desktop.
ManagedObjectContext notifications not firing
//In my app delegate after I setup routes and such:
[[NSNotificationCenter defaultCenter] addObserver:myTableViewController
selector:@selector(mergeChangesFromContextDidSaveNotification:)
name:NSManagedObjectContextDidSaveNotification
object:[RKObjectManager sharedManager].objectStore.managedObjectContext];
//In myTableViewController:
- (void)mergeChangesFromContextDidSaveNotification:(NSNotification *)notification
{
NSLog(@"THIS NEVAR HAPPENZ!@#");
NSManagedObjectContext *mainContext = [self managedObjectContext];
if ([notification object] == mainContext) {
// main context save, no need to perform the merge
return;
}
[self performSelectorOnMainThread:@selector(updateContext:) withObject:notification waitUntilDone:YES];
}
- (void)updateContext:(NSNotification *)notification
{
NSManagedObjectContext *mainContext = [self managedObjectContext];
[mainContext mergeChangesFromContextDidSaveNotification:notification];
[self.tableView reloadData];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment