Re: Sorting through .plist in NSDictionary

On Wed, Mar 25, 2009 at 11:49 PM, Jerry Krinock <jerry@xxxxxxxx> wrote:
> On 2009 Mar 25, at 19:53, Pierce Freeman wrote:
>> I am attempting to sort through the contents of a .plist file in
>> NSDictionary, but am running into some problems. ÂSince .plist files are
>> kind of like a "tree", I can't just call objectForKey as there is no way
>> for
>> me to return the instance that I am looking for. ÂHow would someone get a
>> certain key for each part of the tree?
> -valueForKeyPath:
> If your key path is in the form of an array, use this from my NSDictionary
> helpers...
> - (id)valueForKeyPathArray:(NSArray*)keyPathArray {
> Â ÂNSString* keyPath = [keyPathArray componentsJoinedByString:@"."] ;
> Â Âreturn [self valueForKeyPath:keyPath] ;
> }

Note that this will fail hard if any of your keys have a . in them,
something that's perfectly legal. I would much prefer something like

- (id)valueForKeyPathArray:(NSArray*)keyPathArray {
id obj = self;
for(id key in keyPathArray)
obj = [obj objectForKey:key];
return obj;


Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)

Help/Unsubscribe/Update your Subscription:

This email sent to maillists@xxxxxxxxx