views:

14

answers:

1

Looking for the most succinct way to convert an array of dicts to an array composed of a certain attribute of each dict. eg.

[ { name => 'Visa', value => 'VI' }, { name => 'Mastercard', value => 'MC' }]
=>
 ['Visa', 'Mastercard']
+2  A: 

This should do the trick:

NSArray *nameArray = [yourArray valueForKey:@"name"];

valueForKey: Returns an array containing the results of invoking valueForKey: using key on each of the receiver's objects.

Vladimir
awesome. I was looking at NSArray docs but missed that one. thank you!
Ilia Lobsanov