This article has been archived and is no longer being updated. It may not work with the most recent OS versions.
How To Use Blocks in iOS 5 Tutorial – Part 2
Feb 10 2012
This is a blog post by iOS Tutorial Team member Adam Burkepile, a full-time Software Consultant and independent iOS developer. Check out his latest app Pocket No Agenda, or follow him on Twitter. Welcome back to our tutorial series on using blocks in iOS 5 – with some Storyboard/Interface Builder practice along the way! In […]
By .
One final tip. When you're using a method that takes a block in Xcode, it can autocomplete the block for you, saving yourself time and syntax errors.
For example, type this into Xcode:
NSArray * array;
[array enum
At this point the autocompletion routine will find enumerateObjectsUsingBlock - hit enter to auto-complete that method name. Then hit enter again to auto-complete the block, and it will put in this:
The final completed project code can be downloaded here. If you are familiar with git, I also have the project hosted here at github, with commits at each step if you get stuck at a step.
Hopefully in creating this simple app, you've been able to see the power and simplicity that Blocks add to your dev toolkit, and gotten some ideas of how you can use them in your own projects.
If this is your first exposure to blocks, you've taken a pretty big step. With more and more apps needing asynchronous, networked, and multi-threaded code, blocks will definitely be considered required learning.
There's still more to learn about blocks - specifically in terms of variable capture and the __block keyword. More information about blocks and Grand Central Dispatch can be found here:
Thanks for following along with me on my first (of hopefully many) tutorial for this site, and I hope to hear from you in the forums!
This is a blog post by iOS Tutorial Team member Adam Burkepile, a full-time Software Consultant and independent iOS developer. Check out his latest app Pocket No Agenda, or follow him on Twitter.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.