The void (^)(void) syntax of the ‘completion’ argument type implemented by the UIViewController method:
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion
has piqued my curiosity and I have been unable to find any documentation for it. Please could someone help explain its purpose/meaning?
Many thanks in advance.
Here’s the discussion of blocks from my book:
http://www.apeth.com/iOSBook/ch03.html#_blocks
There’s an example there, but here’s an example that’s closer to the sort of thing you’re asking about:
The completion block takes one parameter, a BOOL called “done”, but this is not used by its code. The idea is that the animation is performed and then the code in the completion block is run.
It’s very important to be comfortable with blocks because they are the way of the future. For example, view animation in iOS 4 uses them, as explained in the “Block Based View Animation” section of my book (read first about the old way, then read about the new iOS 4 way):
http://www.apeth.com/iOSBook/ch17.html#_view_animation
In iOS 5 blocks are even more important; there are more and more situations where they are not optional.
Also blocks are the way to use GCD (grand central dispatch), which is far and away the best way to do multi-threading.