KVO object properties within to-many relationship
I have a Core Data to-many relationship consisting of Parent <--->> Child. I would like to setup a key-value observing mechanism such that when a property (e.g. firstName, lastName) on any of the Child objects changes it triggers a notification. When using the standard KVO syntax:
[self.parentObject addObserver:self forKeyPath:@"children" options:NSKeyValueObservingOptionNew context:NULL]
this only notifies when the relationship itself is modified (i.e. a Child object is added or removed from the relationship), rather than when a property of one of those Child objects changes. Obviously this is how it was designed to operate, so there's nothing wrong with that happening, but how can I instead use KVO to achieve my desired requirement?
Thanks in advance!
AFAIK there is no built-in way to observe collection object properties with a single line of code. Instead you have to add/remove observers when the object is inserted/removed from your collection.
An explanation and a sample project can be found over here: https://web.archive.org/web/20120319115245/http://homepage.mac.com/mmalc/CocoaExamples/controllers.html (See the "Observing a collection is not the same as observing the properties of the objects in a collection" section)
Update: The Link broke - I changed it to an archive.org snapshot.