VBK
VBK

Reputation: 1455

extracting properties from NSArray of objects

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

Answers (2)

Afsal Meerankutty
Afsal Meerankutty

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

JustSid
JustSid

Reputation: 25318

Key Value coding will help you with that:

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

Upvotes: 40

Related Questions