Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

32. Blocks > Return values

Return values

Finally, when a block returns a value, you can call its block variable like a function.

double (^divBlock)(double,double) = ^(double k, double j) {
    return k/j;
}

In this code, you’ve declared divBlock as a block variable that returns a double and expects two doubles as arguments. Then you assigned it a value which includes the instruction to return the result of dividing the two arguments.

You can use this block like so:

double quotient = divBlock(42.0, 12.5);

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint