Created
November 28, 2011 03:29
-
-
Save zigphroid/1398971 to your computer and use it in GitHub Desktop.
ManagedObjectContext notifications not firing
This file contains 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
//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