• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Can a subclass of NSDictionary do this?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Can a subclass of NSDictionary do this?
      • From: Chris Hanson <email@hidden>
  • Prev by Date: Re: Odd NSDictionary Problem
  • Next by Date: Re: Bug reports and documentation updates (was Re: Subclassing NSPort (or NSSocketPort))
  • Previous by thread: Re: Design for Cocoa (was Re: Can a subclass of NSDictionary do this?)
  • Next by thread: Re: Can a subclass of NSDictionary do this?
  • Index(es):
    • Date
    • Thread