views:

36

answers:

1

If I have a plist which is structured like this:

Root              Array
   Item 0         Dictionary
     City         String     New York
     People       Array
        Item 0    String     Steve
        Item 1    String     Paul
        Item 2    String     Fabio
        Item 3    String     David
        Item 4    String     Penny
   Item 1         Dictionary
     City         String     London
     People       Array
        Item 0    String     Linda
        Item 1    String     Rachel
        Item 2    String     Jessica
        Item 3    String     Lou
   Item 2         Dictionary
     City         String     Barcelona
     People       Array
        Item 0    String     Edward
        Item 1    String     Juan
        Item 2    String     Maria

Then what is the most efficient way of getting all the names of the people into one big NSArray?

+2  A: 

The shortest but probably very inefficient way:

return [thePlistArray valueForKeyPath:@"@distinctUnionOfArrays.People"];

the normal way:

NSMutableArray* resArr = [NSMutableArray array];
for (NSDictionary* record in thePlistArray) {
   [resArr addObjectsFromArray:[record objectForKey:@"People"]];
}
return resArr;
KennyTM