Getting return values from a code block
I've never used any async stuff during my time as a developer, so when I came across blocks in Objective-C I was stumped for a bit as to how they work. _Why can't I access any local fields or return this value!_. Now that I have had some exposure I'm more familiar with them and understand how they work. I still have the same issue though; there are times I need to get a value back out of the block. Yes I can post to NSNotificationCenter, but I'd rather not.
I learned you can create an instance of a code block, in which case you can return a value and capture it. As an example, let's say we want to build an array of buttons currently referenced by our view controllers view. I know that you wouldn't really need a block to do something like this. In the real-world I would probably just use the `[NSArray enumerateObjectsUsingBlock:];` method for the purpose of demonstrating return values in blocks though, it'll work.
Read More