Overriding v alueForKeyPath
Overriding v alueForKeyPath
- Subject: Overriding v alueForKeyPath
- From: Laurent Cerveau <email@hidden>
- Date: Wed, 09 Jul 2008 15:39:47 +0200
Hi
I am trying to us KVC in a way that it allows me to add an accessor
semantic to an object so that it can answer to simple valueForKeyPah
call.
For example I want to be able to write [myObject
valueForKeyPath:@"texts.title.en"] which would give me the english
version of the title of my Object
Practically the class is having an ivar that is an other type of
object , itself containing a set of "localized object" (hope this is
not too confusing) . A "normal" way to access this would be to write
somethign like ([myObject.texts objectForLanguageID:1]).title. and 1
ithe ID of english language.
The problem is that because I am not sure that 1 will stay the ID for
english, and because I would like to be sure that at the highest level
the API stays the same , be based on KVC.
When I write the setters with setValueForKeyPath and do the
interpretation of the path in the right way, all is fine. However in
the accessor way this does not go fine and I end up with messages in
the console telling me hings like
[<MOSLanguageObservedMutableSet 0x15aa60d0>
addObserver:<NSKeyValueObservance 0x15a8a0e0> forKeyPath:@"title.de"
options:0x0 context:0x15aa5cb0] was sent to an object that is not KVC-
compliant for the "title" property.
Apparently what is happening is that the keyPath is decomposed, each
object is verified to be KVC compliant for the appropriate subPath and
here we go : nothing unexpected if I refer to the doc except that..the
part I do not understand in this case is the following : why is own
valueForKeyPath for this object not called at first place in this case?
Thanks
laurent
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden