开发者

ObjectiveC/iphone: convert an array of dicts to an array composed of a certain attribute of each dict

开发者 https://www.devze.com 2023-01-08 21:03 出处:网络
Looking for the most succinct way to convert an array of dicts to an array composed of a certain attribut开发者_如何转开发e of each dict. eg.

Looking for the most succinct way to convert an array of dicts to an array composed of a certain attribut开发者_如何转开发e of each dict. eg.

[ { name => 'Visa', value => 'VI' }, { name => 'Mastercard', value => 'MC' }]
=>
 ['Visa', 'Mastercard']


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消