Question

I am trying to find a way of observing a Core Data relationship (more specifically the removed items of an unordered relationship) before it gets actually changed. You can imagine it as a "will change" notification known from other Cocoa APIs.

The reason is that I want to update the UI according to these changes and I need a parameter which isn't stored in the managed objects but in an other data structure (in my case it's the index from a NSArrayController). I can retrieve the parameter only if the items weren't removed from the relationship yet.

The only way of getting such "will change" notifications I could find was to override the KVO method -willChangeValueForKey:withSetMutation:usingObjects: in the custom NSManagedObject subclass and forward this information. The problem is the documentation says: "You must not override this method." and this makes me want to find a better solution.

  1. Is the "will change" approach right in this case?
  2. If so, how could I achieve it? If not, how should I solve the mentioned problem in another way?
Was it helpful?

Solution

You can just override the relationship’s setter method instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top