Created
February 1, 2012 19:38
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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