Re: NSKeyValueCoding tips
Re: NSKeyValueCoding tips
- Subject: Re: NSKeyValueCoding tips
- From: Ryan Dingman <email@hidden>
- Date: Mon, 28 Jan 2002 23:57:01 -0800
On Monday, January 28, 2002, at 11:15 PM, Aaron Tuller wrote:
Are there are any built in objects that NSKeyValueCoding is implemented
for?
NSKeyValueCoding is implemented on NSObject as a category. So all
objects that inherit from NSObject (which is most of them) will respond
to those methods.
Ideally I'm looking for a way to chain NSDictionary like objects
together so like I can do something like:
[someDict valueForKeyPath:@"key1.key2.key3"];
and have it do:
[[[someDict objectForKey:@"key1"] objectForKey:@"key2"]
objectForKey:@"key3"]
-valueForKeyPath: will do exactly what you want in this case.
plus all the other neat KVC stuff.
should I implement it as a category on NSDictionary? Has someone else
already done that? Am I tackling it the wrong way?
NSDictionary inherits from NSObject so see above. There is no need to
do this.
Also, I'm doing this because I parsed some XML as a property list using
OmniExpat and using the path style way to dig into the tree of objects
seems like the way to go.
Thanks for any suggestions.
Oh, also, are the path methods already made so I only need to implement
valueForKey: and magically valueForKeyPath: will parse the path and
call valueForKey:. Is that on NSObject already? I did a:
Yes, -valueForKeyPath: will parse the key path and then call
-valueForKey: with all of the components. It is very rare that you
should need to implement -valueForKey: but if you have a class that
needs to implement it in a special way you can expect -valueForKeyPath:
to do the right thing.
grep valueForKey *
on the headers and found nothing except in the NSKeyValueCoding.h file
If you look carefully, NSKeyValueCoding is just a category on NSObject.
Hope this helps.
ryan
--
Ryan Dingman
FrontBase, Inc.
email@hidden
-aaron
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.