首页 > 代码库 > Blocks
Blocks
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。