Cover by Joe Conway, Aaron Hillegass

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required