Simple list of sub category
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>th开发者_开发百科eme</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.
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.
精彩评论