什么是JS的`map()`函数的Objective-C等价物? [英] What's the Objective-C equivalent of JS's `map()` function?
本文介绍了什么是JS的`map()`函数的Objective-C等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是JS的 map()
函数的Objective-C等价物?我是否只使用NSFastEnumeration并自己应用该函数?
What's the Objective-C equivalent of JS's map()
function? Would I just use NSFastEnumeration and apply the function myself?
推荐答案
您可以使用 NSArray
的 enumerateObjectsUsingBlock:
如果您使用的是OS X 10.6或iOS 4。:
You can use NSArray
's enumerateObjectsUsingBlock:
if you're on OS X 10.6 or iOS 4.:
NSMutableArray *mapped = [NSMutableArray arrayWithCapacity:[array count]];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
id mapObj = DoSomethingToObject(obj);
[mapped addObject:mapObj];
}];
(无耻但相关的插件:我有一个库,它将地图和其他类似功能添加到 NSArray
和 NSSet
。)
(Shameless but relevant plug: I have a library for OS X and iOS that adds map and other similar functionality to NSArray
and NSSet
.)
这篇关于什么是JS的`map()`函数的Objective-C等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文