Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@preble
Last active December 15, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preble/5306137 to your computer and use it in GitHub Desktop.
Save preble/5306137 to your computer and use it in GitHub Desktop.
Using Objective-C blocks for encapsulation while preparing a local variable.
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