Typical Block Usage

In this chapter, our examples have been pretty trivial. In the next chapter, you will see some real world examples of blocks and see just how useful they can be. However, to whet your appetite a bit, let’s talk about how blocks are typically used.

Most commonly, blocks are used as callbacks. For example, in Chapter 13 you supplied a block when dismissing a modal view controller. When the dismissal completed, the block was executed. Thus, you can think of blocks as a one-shot callback for an event to occur some time in the future. We usually call a block used in this manner a completion block.

Using a completion block is usually much simpler than setting up a delegate or a target-action pair. You don’t have to declare or ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.