Blocks

Blocks are a recent extension to the C language. They are not part of the standard ANSI C definition and were added to the language by Apple, Inc. Blocks look and act a lot like functions. The syntax takes some getting used to. You can pass arguments to blocks, just like you can to functions. You can also return a value from a block. Unlike a function, a block can be defined inside a function or method, and gets to access any variables defined outside the block that are within its scope. In general, such variables can be accessed, but their values cannot be changed. There is a special __block modifier (two underscore characters precede the word block) that enables you to modify the value of a variable from inside the block, and you’ll ...

Get Programming in Objective-C, Sixth Edition 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.