extracting properties from NSArray of objects

只谈情不闲聊 提交于 2019-12-05 10:27:10

问题


Is there any of way (other than looping) of extracting a particular property of all objects in an array. So say there in an array of people. I want to extract all their first names into an array.


回答1:


Key Value coding will help you with that:

NSArray *result = [people valueForKey:@"firstname"];



回答2:


I got answer for my question. This is how we can achieve the same in swift.

let arraytWithProperties = arrayWithObjects.map{ $0.propertyName }


来源:https://stackoverflow.com/questions/12312032/extracting-properties-from-nsarray-of-objects

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