Reputation: 1455
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.
Upvotes: 21
Views: 4434
Reputation: 366
I got answer for my question. This is how we can achieve the same in swift.
let arraytWithProperties = arrayWithObjects.map{ $0.propertyName }
Upvotes: -1
Reputation: 25318
Key Value coding will help you with that:
NSArray *result = [people valueForKey:@"firstname"];
Upvotes: 40