2
votes

I want to respond to changes of certain NSManagedObjects that have been added, updated, or deleted.

I have an issue with the deleted objects, though: all relationships to other objects are now nil.

Is there a way to get this kind of notification before the object is affected this way?

Edit:

This is basically my delete code:

  [moc deleteObject:myObject];

  id saveBlock = ^{
      NSError *error = nil;
      BOOL     saved = NO;

     saved = [self save:&error];

    // error handling.
  };

  [moc performBlockAndWait:saveBlock];
1
I just discovered this issue myself. I know this question is years old, but do you happen to remember what you found? - SAHM
@SAHM I think I created a custom notification and posted that at the appropriate time, passing in the object in question. - Ants

1 Answers

2
votes

If you are wanting to react to deletions then you should be listening for NSManagedObjectContextWillSaveNotification and watch for the NSDSeletedObjectsKey come through as part of the notification. That is the last chance before deletion to deal with them.