Recently, there was a question about blocks that I couldn’t answer so I took a note to review it.
I came upon some great articles. Seeing the same elephant described by different people invariably leads to a comprehensive understanding of the elephant (much in the same way that taking beginner swing dance classes from 4-5 people leads to better fundamentals).
With no desire to write an inferior blog post, I’m going to review the ones I found, much the same way that I review restaurants.
Mike Nachbaur: Using GCD and Blocks Effectively
Tutsplus: Objective-C Succinctly: Blocks
AppCoda: Introduction to Objective-C Blocks
Apple Working with Blocks
Matt Nunogawa Objective C Blocks: Summary, Syntax & Best Practices
Conrad Stoll Blocks, Operations, and Retain Cycles
I’ll be looking at:
- explanation of why it’s important
- completeness vs depth
- the example code
- ease of transferring examples to projects
- how beginner friendly it is
Which should I read first?
Starting from Square One
Go with Tutsplus: Objective-C Succinctly: Blocks. It’s short, has useful examples and memory is well explained with diagrams. It stops short of retain loops though, which is a vital topic. Also lacking is why blocks are used (when would I want to use a block? what would I have used otherwise?).
AppCoda (Introduction to Objective-C Blocks) is really known for their app tutorials. They explain very well why you would use blocks and lead you through an example of how it would be used in a practical situation with an actual app.
Mike Nachbaur: Using GCD and Blocks Effectively extends deeper into asynchronous callbacks, introduces Grand Central Dispatch, and the idea that retain cycles can happen.
For Programmers from Other Languages
Matt Nunogawa (Objective C Blocks: Summary, Syntax & Best Practices) writes his blog directed at programmers from other languages and overviews blocks with greater examples for retain cycles and how to avoid them.
Bonus: Conrad Stoll (Blocks, Operations, and Retain Cycles) writes about a real example of a bug that his team faced with retain cycles and blocks.
For Quick Reference After Learning It Once
Apple Working with Blocks documentation can be a bit dry and doesn’t give much guidance for when to use it, but if that doesn’t bother you, then by all means go ahead. It’s very comprehensive.