Re: nested NSDictionary's and objectForKey
Re: nested NSDictionary's and objectForKey
- Subject: Re: nested NSDictionary's and objectForKey
- From: Russell Gray <email@hidden>
- Date: Sat, 19 Sep 2009 18:46:58 +1000
That is what I need to do, I should clarify a little. I have one
plist. Inside that plist, is an NSDictionary with multiple keys, one
of the keys is an NSArray with multiple keys. (some NSDictionaries,
and NSStrings. One of the NSDictionaries contains an NSArray with
multiple keys.....
I want to get all the keys "myKeys" from all levels of the tree
structure, and add them to "myArray"
how would i go about that?
On 19/09/2009, at 5:57 PM, Quincey Morris wrote:
On Sep 19, 2009, at 00:34, Russell Gray wrote:
I am wanting to create an NSArray from strings stored (at various
levels) in a plist of nested NSDictionary's.
I am trying the following code, but it only reads the key from the
root dictionary: (FolderPath, and PlistFullName, have been
previously defined)
Code:
NSString *plistFolder = [FolderPath stringByExpandingTildeInPath];
NSString *PlistPath = [plistFolder
stringByAppendingPathComponent:PlistFullName];
NSDictionary *myDictionary = [NSDictionary
dictionaryWithContentsOfFile: PlistPath];
NSArray *myArray = [myDictionary objectForKey:@"myKey"];
where do I begin?
Is there just one file involved? If not, you can use NSFileManager
methods to traverse the relevant directory structure as an "outer"
loop.
For building the array, you can simply traverse the nested
dictionary structures recursively. Move the traversal code into a
separate method. In that method, use 'isKindOfClass:' to determine
whether each object is a string or a dictionary. If the former, add
the string to your array. If the latter, call your traversal method
recursively for the sub-dictionary.
Is that what you're asking?
_______________________________________________
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
_______________________________________________
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