Question

I have a NSManagedObject subclass (Parent) that has an ordered to-many relationship with another NSManagedObject subclass (Child). I require Parent to use KVO to watch a value on the Child(ren) held in its NSOrderedSet. This means I need to manually add and remove the Parent as an observer when a Child is added-to or removed-from the set. This means I need to implement my own accessors for the NSOrderedSet.

Where can I see what these accessors should look like?

Was it helpful?

Solution

No. Observe the collection as a whole and allow the OS to handle observation for each child. Observe the keypath to the property from the vantage point of the parent. In other words, the parent will be observing itself via a keypath which goes though the children.

[self addObserver: self forKeyPath: @"childs.observedProperty" options: ... context: ...];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top