Search code examples
ioscore-datansnotificationcenterios10

How to find out which MOC concerned by NSManagedObjectContextObjectsDidChange


How can I recognize which MOC did change when receiving a NSManagedObjectContextObjectsDidChange notification. Apparently userInfo employs a key "managedObjectContext", but I have not found this one documented among other keys.

The reason I am asking is that I need to trigger some action after a child MOC was saved. The trigger must fire only once, but it looks as if I receive the notification twice, perhaps once for the child MOC and once for its parent.


Solution

  • It's in the object property of the NSNotification.

    - (void)contextDidChange:(NSNotification *)notification
    {
        NSManagedObjectContext *context = notification.object;
    }