2010-06-08 4 views
0

Si j'ai un plist qui est structuré comme suit:Méthode efficace pour obtenir toutes les matrices de plist dans un tableau?

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 

Alors quelle est la façon la plus efficace d'obtenir tous les noms des personnes dans un grand NSArray?

Répondre

4

Le chemin le plus court, mais probablement très inefficace:

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

la voie normale:

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