I have an implementation of Core Data where I need to listen to the NSManagedObjectContextDidSaveNotification
notification, but it simply doesn't get dispatched.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(method:)
name:NSManagedObjectContextDidSaveNotification
object:nil];
In my implementation if I switch to the NSManagedObjectContextWillSaveNotification
everything works as expected, ie, my method:
selector gets invoked.
To trigger the notification, I'm simply doing this:
NSManagedObject *object = [NSEntityDescription
insertNewObjectForEntityForName:@"Object"
inManagedObjectContext:_moc];
if (![_moc save:nil]) {
NSLog(@"saving successful, expecting notification dispatch");
}
But nothing... Please halp
EDIT: If I manually post the notification NSManagedObjectContextDidSaveNotification
inside the save if
statement, it gets dispatched and my method:
gets called, but my NSManagedObjectContext
just won't do it automatically on save as it should...