码迷,mamicode.com
首页 > 其他好文 > 详细

Blocks

时间:2014-06-30 15:21:04      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   cti   io   res   

Blocks are a way to define a block of code that you will use at a later time.

Sometimes people refer to blocks as anonymous functions because they are functions that aren’t
attached to an entity.

 

eg:

squareThis = ^(float x){
  return x * x;
};

 

float result = squareThis(4);
NSLog(@"result = %f", result);

This will print out the following output to the console log:
result = 16.000000

NSString *title = @"Multiply Block Execution";
float (^multiplyThese)(float, float) = ^(float x, float y)
{
    NSLog(title);

    return x * y;
};

 

NSLog(@"multiplyThese(3,4) = %f", multiplyThese(3,4));

Output:

Multiply Block Execution
multiplyThese(3,4) = 12.000000

 

 

 

 

Blocks,布布扣,bubuko.com

Blocks

标签:style   blog   color   cti   io   res   

原文地址:http://www.cnblogs.com/davidgu/p/3816284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!