Last active
December 15, 2015 18:48
-
-
Save preble/5306137 to your computer and use it in GitHub Desktop.
Using Objective-C blocks for encapsulation while preparing a local variable.
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
NSArray *things = ^{ | |
NSMutableArray *tmpArray = [NSMutableArray arrayWithCapacity:numThings]; | |
for (int i = 0; i < numThings; i++) | |
{ | |
[tmpArray addObject: ... ]; | |
} | |
return [tmpArray copy]; | |
}(); | |
// Using a category method: | |
NSArray *things = [NSArray ap_arrayViaMutable:^(NSMutableArray *a) { | |
[a addObject: ... ]; | |
... | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment