#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//block的规则
//返回值类型(^block名称)(形参参数列表)一般形参变量名不用写= ^返回值类型(实参数列表){block体};
// int (^block3)(int) = ^(int)(int x){ return 101;};
//int result=block(3);调用
//注意要访问修改局部变量的话,需要在该变量前加__block关键字
__block int n=10;
void(^block1)(void)=^(void)
{
n=100;
NSLog(@"%d\n",n);
};
block1();
int (^sum)(int,int)=^int (int x,int y)
{
return x+y;
};
int result=sum(3,5);
NSLog(@"%d",result);
}
原文:http://www.cnblogs.com/thbbsky/p/3751332.html