6 comments

[ 2.8 ms ] story [ 24.2 ms ] thread
(comment deleted)
That's cool, but it's actually possible to use recursive blocks directly if you simply declare the block as a __block variable. This works perfectly fine:

  __block void (^myBlock);
  myBlock = ^{ myBlock(); };
  myBlock();
The only thing you have to watch out for is when the block gets copied prior to its invocation (e.g. if you pass it to some function that does a Block_copy on it). In that case you have to first copy the block yourself and update your block variable:

  __block void (^myBlock);
  myBlock = [^{ myBlock(); } copy];
  someFunctionThatCopiesTheBlock(myBlock);
Heh, I was wondering when someone would bring this up. For most cases, this also works. I will say that I've seen cases where this technique hasn't worked, but those were all far, far more complex than most any Obj-C programmer will ever need to worry about.
This has to be the most unboring README file I ever read. The fun.m and nofun.m have a nice touch too.
I really appreciate the overview that author gave in readme. Quite often links to seemingly interesting github projects are submitted, but I am unable to figure out the 'really cool' parts. Explanation adds much value to playing with the project.
I just don't get what this is useful for. Can someone enlighten me?