问题
I have an NSArray
filled with NSDictionaries
. One of the keys the dicts have in common is "name". I have another array, filled with names. I want to search the first array, if it finds a name it is supposed to add the dictionary to a third mutable array. The third array then contains all dictionary which names are in the name-array.
回答1:
Use "fast enumeration", commonly also known as for-in loop:
for (NSDictionary* dict in myArray) {
Also, to compare NSString's, use -isEqualToString:.
if ([[dict objectForKey: myKey] isEqualToString:myString]) {
}
来源:https://stackoverflow.com/questions/6241537/search-nsarray-of-nsdictionary