How to do that without having to \"scroll\" the entire given array with a \"for\" loop?
I wrote a dictionary method on NSArray to be able to write cleaner functional code
-(NSArray *)arrayByPerformingBlock:(id (^)(id))performBlock
{
NSMutableArray *array = [NSMutableArray array];
for (id element in self)
[array addObject:performBlock(element)];
return [NSArray arrayWithArray:array];
}
usage:
arrayWithStrings = [arrayWithStrings arrayByPerformingBlock:^id(id element) {return [[element mutableCopy] autorelease];}];
This was inspired by list comprehensions I know from Python. I also wrote versions of this methods with testing. See my arraytools.