• 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
reading a plist
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

reading a plist


  • Subject: reading a plist
  • From: Koen van der Drift <email@hidden>
  • Date: Sat, 20 Jul 2002 22:10:17 -0400

Hi,

I am trying to read some values from a plist. I know how to read in the
whole list (see eg Hillegass' book page 335). What I cannot figure out from
the NSDictionary information is how to get the value that belongs to a
certain key in a 'multilevel' plist. Here's a snippet of my test.plist:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>testkeys</key>
<dict>
<key>KeyA</key>
<dict>
<key>KeyA1</key>
<string>6</string>
<key>KeyA2</key>
<string>20</string>
<key>KeyA3</key>
<string>Heptose</string>
<key>KeyA4</key>
<string>6</string>
<key>KeyA5</key>
<string>40</string>
</dict>
<key>KeyB</key>
<dict>
<key>KeyB1</key>
<string>6</string>
<key>KeyB2</key>
<string>0</string>
<key>KeyB3</key>
<string>Heptose</string>
<key>KeyB4</key>
<string>6</string>
<key>KeyB5</key>
<string>0</string>
</dict>
...
...
</dict>
</dict>

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)?


many thanks,

- Koen.
_______________________________________________
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: reading a plist
      • From: Chris Hanson <email@hidden>
    • Re: reading a plist
      • From: Kyle Moffett <email@hidden>
    • Re: reading a plist
      • From: Thomas Harrington <email@hidden>
  • Prev by Date: Re: Dificult question continue
  • Next by Date: Re: Contents of a directory?
  • Previous by thread: Re: Contents of a directory?
  • Next by thread: Re: reading a plist
  • Index(es):
    • Date
    • Thread