Re: Can a subclass of NSDictionary do this?
Re: Can a subclass of NSDictionary do this?
- Subject: Re: Can a subclass of NSDictionary do this?
- From: p3consulting <email@hidden>
- Date: Wed, 23 Jul 2003 09:29:16 +0200
>
> I was implementing a subclass of NSObject which contained an
>
> NSMutableDictionary.
>
> The purpose is to support a storage container for nested
>
> NSDictionaries to allow me to
>
> search by keys having internal structure.
>
>
>
> for a call [self lookup: k inDict: d]
>
>
>
> The key@ "a.b.c" would do the following
>
> lookup: k inDict: d
>
> v = [d objectForKey: @"a"]
>
> if ([v isKindOfDictionary])
>
> return [self lookup: @"b.c" inDict: d]
>
> else return v;
>
>
>
> this would reduce to looking up @"c" in the subdictionary @"a.b"
>
> Thus a single call to lookup would traverse a path through the set of
>
> nested dictionaries to find a value.
>
>
This is built in actually. Look at the documentation for
>
NSKeyValueCoding. Specifically, you'll get exactly the result you want
>
by calling [d valueForKeyPath:@"a.b.c"].
>
NSKeyValueCoding is limited in functionality for general use
(WebObject/EOFramework origin ?), for example in doesn't support array
in the path syntax
(e.g. "a.b[1].c") and the takeValue:forKeyPath: doesn't create the
intermediary path items if they don't already exist
(ok this should be a parameter)
Some may want something more general
Pascal Pochet
P3 Consulting
email@hidden
http://www.p3-consulting.net
_______________________________________________
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.