Looking for the most succinct way to convert an array of dicts to an array composed of a certain attribute of each dict. eg.
寻找将dicts数组转换为由每个dict的某个属性组成的数组的最简洁方法。例如。
[ { name => 'Visa', value => 'VI' }, { name => 'Mastercard', value => 'MC' }]
=>
['Visa', 'Mastercard']
1 个解决方案
#1
2
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.
valueForKey:返回一个数组,其中包含调用valueForKey:在每个接收者对象上使用键的结果。
#1
2
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.
valueForKey:返回一个数组,其中包含调用valueForKey:在每个接收者对象上使用键的结果。