我有一个包含字典对象的数组。在每个字典中,键都是通用的。现在我想获取该键的所有值。我通过迭代获得了这些值,但我正在寻找一些直接的方法或默认方法来完成这项工作。
你能帮我找到一种可以达到目的的默认方法吗?谢谢。
数据结构是这样的:
<array>
<dict>
<key>Match</key>
<string>Football</string>
<key>Stadium</key>
<string>XXXXX</string>
</dict>
<dict>
<key>Match</key>
<string>HOCKY</string>
<key>Stadium</key>
<string>XXXXX</string>
</dict>
</array>
我现在正在这样做:
NSMutableArray * matches = [[NSMutableArray alloc] init];
for (int i = 0; i< myArray.count; i++){
[matches insertObject:[[myArray objectAtIndex:i] objectForKey:@"Match"] atIndex:i];
}
[matchDataArray addObjectsFromArray:matches];
它给了我正确的答案。但我不想做这个迭代。我想要一个方法,它可以从数组的所有索引中返回“匹配”键的所有值,并立即保存在另一个数组中。新创建的数组将只有数组所有索引中的 Match 键的值。
这可能吗??