Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Last active December 25, 2015 07:38
Show Gist options
  • Save jspahrsummers/6940184 to your computer and use it in GitHub Desktop.
Save jspahrsummers/6940184 to your computer and use it in GitHub Desktop.
lol recursive blocks
__block void (^myRecursiveBlock)(int);
id myBlock = ^(int x) {
if (x > 5) {
// Release the block from its own implicit retain cycle.
myRecursiveBlock = nil;
} else {
myRecursiveBlock(x + 1);
}
};
// Avoids analyzer warnings about retain cycles.
myRecursiveBlock = [myBlock copy];
myRecursiveBlock(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment