0

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?
Lukáš Kubánek
  • 946
  • 1
  • 15
  • 27

1 Answers1

1

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

Wil Shipley
  • 9,343
  • 35
  • 59
  • To be exact, I am going to override the mutation methods, not the setter, but that's the way to go! Thanks! – Lukáš Kubánek Jan 12 '14 at 16:48
  • You wrote: "The reason is that I want to update the UI according to these changes " - So now you are modifying your UI from your model code? Btw: Hi Wil! :D – Christian Kienle Jan 14 '14 at 17:15