Block Basics

In many ways, a block is like an anonymous function: It can take arguments, it can return a value, and a symbol can be used to call a block. But blocks are much more than this. Using them is a way to pass inline “functions” as method arguments. And most powerfully of all, blocks have access to all the variables that are in scope at the time they are defined. Or put another way, a block is a closure that has access to any variable the creating method can access at the point when the block is defined.

Before you can use blocks, you need to know how to declare, use, and write them.

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming 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.