标签:copy number word cti second class turn str pes
//block 的申明,定义,调用,block快捷方式inline
//<#returnType#>(^<#blockName#>)(<#parameterTypes#>) = ^(<#parameters#>) {
// <#statements#>
//};
// blockName(parameters);
//frist method
void(^block1)() = ^{
NSLog(@"调用了block1");
};
block1();
//second method ,如果没有参数,参数可以隐藏,如果有参数,定义的时候,必须要写参数,而且必须要有参数变量名
void(^block2)(int) = ^(int a){
};
block2(2);
//third method ,block式右边定义返回类型可以省略,不管有没有返回值,都可以省略
//没省略
int(^block3)() = ^int{
return 3;
};
block3();
//省略
int(^block4)(NSString *) = ^(NSString *b){
return 4;
};
block4(@"hello");
@property (nonatomic, copy) 返回值类型 (^block的名称)(参数类型);
@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
- (void)方法名:(返回值类型 (^)(参数类型))block的名称;
- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;
[对象/类 方法名:^返回值类型 (参数) {...}];
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
typedef 返回值类型 (^类型名称)(参数类型);
类型名称 block的名称 = ^返回值类型(参数) {...};
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
标签:copy number word cti second class turn str pes
原文地址:http://www.cnblogs.com/Cassiedou/p/7141402.html