Re: reading a plist
Re: reading a plist
- Subject: Re: reading a plist
- From: Kyle Moffett <email@hidden>
- Date: Sun, 21 Jul 2002 00:59:33 -0400
On Saturday, July 20, 2002, at 10:10 PM, Koen van der Drift wrote:
>
If I use the code example from Hillegass' book:
>
>
path = [[NSBundle mainBundle] pathForResource:@"test"
>
ofType:@"plist"];
>
>
myList = [NSDictionary dictionaryWithContentsOfFile: path];
>
myArray = [myList objectForKey:@"testkeys"];
>
NSLog(@"test = %@", myArray);
>
>
Then I get all keys and values. If I use myArray = [myList
>
objectForKey:@"KeyA2"] then myList is null.
>
>
So, how do I store in an array all the values from a similar key, for
>
instance KeyA3, KeyB3, etc? And is it possible to get an array with
>
KeyA,
>
KeyB, ... (thus not the values)?
It seems you got quite confused here, you get the "testkeys" dictionary
from
the file, then try to branch two levels down to get at KeyA2 with one
objectForKey. Try this:
NSDictionary *myList = [NSDictionary dictionaryWithContentsOfFile: path];
NSString *myString = [[[myList objectForKey:@"testkeys"]
objectForKey:@"KeyA"] objectForKey:@"KeyA2"];
You just skipped past a step, you cannot get at KeyA2 without accessing
KeyA.
[...]
<key>testkeys</key>
<dict>
<key>KeyA</key>
<dict>
[...]
<key>KeyA2</key>
<string>20</string>
[...]
</dict>
[...]
</dict>
[...]
>
many thanks,
>
>
- Koen.
You are very welcome,
Kyle Moffett
_______________________________________________
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.