搜索nsarray的nsdictionary [英] Search nsarray of nsdictionary
本文介绍了搜索nsarray的nsdictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSArray
充满 NSDictionaries
。其中一个键的共同点是名称。我有另一个数组,填充名称。我想搜索第一个数组,如果它找到一个名称,它应该添加到第三个可变数组的字典。
解决方案
使用快速枚举,通常也是已知的as for-in loop:
for(NSDictionary * dict in myArray){
此外,为了比较NSString,请使用-isEqualToString:。
if([[dict objectForKey:myKey] isEqualToString:myString]){
}
I have an
NSArray
filled withNSDictionaries
. 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]) { }
这篇关于搜索nsarray的nsdictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文