jeudi 13 août 2015

Equivalent of .map in Swift in Objective C?

Say I have NSArray *x = @[@1, @2, @3, @4];

Now say I want an array like @[@2, @4, @6, @8]

In good ole Swift, I can just do :

xDoubled = x.map({($0) * 2})

Can someone tell me how I can do this in Objective-C without doing -

NSMutableArray *xDoubled = [NSMutableArray new];
for (NSInteger xVal in x) {
    [xDoubled addObject:xVal * 2];
}

?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire