开发者

Search nsarray of nsdictionary

开发者 https://www.devze.com 2023-03-11 00:06 出处:网络
I have an NSArray filled with NSDictionaries开发者_Go百科. 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

I have an NSArray filled with NSDictionaries开发者_Go百科. 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.


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]) {

   }
0

精彩评论

暂无评论...
验证码 换一张
取 消