Will this lead to any sort of retain cycle? Is it safe to use?
__block void (^myBlock)(int) = [^void (int i)
{
if (i == 0)
return;
NSLog(@\"
Here is a modern solution to the problem:
void (^myBlock)();
__block __weak typeof(myBlock) weakMyBlock;
weakMyBlock = myBlock = ^void(int i) {
void (^strongMyBlock)() = weakMyBlock; // prevents the block being delloced after this line. If we were only using it on the first line then we could just use the weakMyBlock.
if (i == 0)
return;
NSLog(@"%d", i);
strongMyBlock(i - 1);
};
myBlock(10);