views:

45

answers:

1

I have a plist with categories :

<array>
<dict>
 <key>part</key>
 <string>up</string>
 <key>house</key>
 <array>
  <dict>
   <key>name</key>
   <string>name1</string>
   <key>theme</key>
   <string>theme1</string>
   <key>image</key>
   <string>image1.png</string>
  </dict>
 </array>
</dict>
<dict>
 <key>part</key>
 <string>down</string>
 <key>house</key>
 <array>
  <dict>
   <key>name</key>
   <string>name2</string>
   <key>theme</key>
   <string>theme4</string>
   <key>image</key>
   <string>image2.png</string>
  </dict>
  <dict>
   <key>name</key>
   <string>name3</string>
   <key>theme</key>
   <string>theme2</string>
   <key>image</key>
   <string>image3.png</string>
  </dict>
 </array>
</dict>

But I would like also have an array with only the list of all the names. I tried NSArray* allSecretsWithDuplicates = [data valueForKeyPath:@"part.name"]; The problem is it return an array of dictionaries.

+1  A: 

You just have to walk the structure yourself - write a method that takes in a dictionary, gets values for all keys and when it finds an array calls itself again for each dictionary in the array. When it comes across a key named "name" have it store the value into either a class local mutable array, or a mutable array that you pass along as you call yourself.

Kendall Helmstetter Gelner