Search nsarray of nsdictionary

牧云@^-^@ 提交于 2019-12-24 13:45:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!