I would like to observe a property on models contained in an NSArray. I can’t use a keyPath of “arrayOfModels.property”, because NSArray throws an exception on
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;
Instead, the docs say to use
- (void)addObserver:(NSObject *)observer toObjectsAtIndexes:(NSIndexSet *)indexes forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;
So does that mean I’d also have to listen to “arrayOfModels” itself, so that when its elements change, I can remove listeners from the old elements and attach them to the new elements? I was hoping KVO would be awesome enough to take care of this for me somehow…
Doesn’t seem like there’s a built-in way to do this, so I’m just removing old listeners and adding new ones when the array membership changes.