开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜