O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Mikey Ward, 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

More on blocks

Here are some other things you can do with blocks.

Return values

The block that you created for VowelMovement does not have a return value, but many blocks will. When a block returns a value, you can get the return value by calling the block variable like a function.

Let’s look again at one of the sample blocks you saw at the beginning of the chapter:

^​(​d​o​u​b​l​e​ ​d​i​v​i​d​e​n​d​,​ ​d​o​u​b​l​e​ ​d​i​v​i​s​o​r​)​ ​{​
 ​ ​ ​ ​d​o​u​b​l​e​ ​q​u​o​t​i​e​n​t​ ​=​ ​d​i​v​i​d​e​n​d​ ​/​ ​d​i​v​i​s​o​r​;​
 ​ ​ ​ ​r​e​t​u​r​n​ ​q​u​o​t​i​e​n​t​;​
}​

This block takes two doubles and returns a double. To store this block in a variable, you would declare a variable of that type and assign the block to it: ...

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