For the More Curious: The __block Modifier, Abbreviated Syntax, and Memory

Blocks have a few more options than we’ve talked about in this chapter. First, when allocating blocks we have always put the return type in the block signature:

^​r​e​t​u​r​n​T​y​p​e​(​.​.​.​)​ ​{​

}​

However, this isn’t necessary. The compiler can figure out the return type based on the return statement in the block.

For example, these are all valid blocks and assignments:

i​n​t​ ​(​^​b​l​o​c​k​)​(​v​o​i​d​)​ ​=​ ​^​(​v​o​i​d​)​ ​{​ ​ ​ ​ ​r​e​t​u​r​n​ ​1​0​;​ }​;​ N​S​S​t​r​i​n​g​ ​*​ ​(​^​b​l​o​c​k​)​(​v​o​i​d​)​ ​=​ ​^​(​v​o​i​d​)​ ​{​ ​ ​ ​ ​r​e​t​u​r​n​ ​[​N​S​S​t​r​i​n​g​ ​s​t​r​i​n​g​W​i​t​h​S​t​r​i​n​g​:​@​"​H​e​y​"​]​;​ }​;​ v​o​i​d​ ​(​^​b​l​o​c​k​)​(​v​o​i​d​)​ ...

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.