I have a class (call it classA) that contains a property named info
(a model class, containing lots of info), wich in turn contains a property named name
(a string). I want another class (classB) to receive a KVO notification when the string name
changes in classA.
This is what I'm doing now on classB:
[classA addObserver: self forKeyPath: @"info.name" options: 0 context: nil];
There are two ways the value name
changes on classA: when it is set directly like classA.info.name = ...
and when info
is set like classA.info = ...
When name
is changed directly KVO works perfectly. However, when the info
property is set and name
changes indirectly, I get this error:
Cannot update for observer <classB> for the key path "info.name" from <classA>, most likely because the value for the key "info" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the classA class.
What should I change on classA to make this work?
willChangeValueForKey:
before anddidChangeValueForKey:
after changing a property? – trojanfoename
is set directly by a view-based tableview, using bindings, so there I can't do anything.info
is set by me, and I'm not doing that. I've tried what you said just now and it still doesn't work. Same error. Oh, and by the way, I created this model class (classA) – Alexname
property. – trojanfoename
is bound to a textfield in a tableview. Perhaps you mean the code to change theinfo
property? Here:[classA setInfo: newInfo]
It's kinda what you'd expect. – Alexwill/didChangeValueForKey:@"info.name"
before and after that? – trojanfoe