I'm using core data to persist my data model which is very simple, three entities like this: A<-->>B<-->>C. When something change in my model I need to perform some activity. To do so, I'm using listening to NSManagedObjectContextObjectsDidChangeNotification, using the following code in viewDidLoad:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateReminder:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.managedObjectContext];
In the method updateReminder I do what needed. The problem is that when the notification execute the changes aren't persisted. If new entity was created not get saved, if something is changed the change don`t get saved. Any ideas?
EDIT: The code of updateReminder is as follows:
- (void)updateReminder:(NSNotification *)notification
{
A *entityAUpdated = [[notification userInfo] objectForKey:NSUpdatedObjectsKey];
if (entityAUpdated) {
...Do something when entityA is updated.
}
A *entityADeleted = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
if (entityADeleted) {
...Do something when entityA is Deleted.
}
A *entityAInserted = [[notification userInfo] objectForKey:NSInsertedObjectsKey];
if (entityAInserted) {
...Do something when entityA is Inserted
}
}