Skip to content

Instantly share code, notes, and snippets.

@jrwren
Created February 1, 2012 19:38
Show Gist options
  • Select an option

  • Save jrwren/1718828 to your computer and use it in GitHub Desktop.

Select an option

Save jrwren/1718828 to your computer and use it in GitHub Desktop.
nsarray map with block... yes, I don't know what I"m doing.. but I'll save this spike and someday I'll know
@interface NSArray (Map) {
}
//[fruitBasket mapWithBlock: ^(id x){ return [x peeledFruit]; }];
- (NSArray *)mapWithBlock: (id (^)(id obj))block;
@end
@implementation NSArray (Map)
- (NSArray *)mapWithBlock: (id (^)(id obj))block{
NSMutableArray *array = [[NSMutableArray alloc] init ];
for (id item in self) {
[array addObject:block(item)];
}
return array;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment