O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide by Joe Conway, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​)​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required