objective-c block
void foo(int (^blkParam)()){ NSLog(@"foo param %d",blkParam()); } void run() { //定义 返回值类型 (^block的名称)(参数类型) = ^返回值类型(参数) {...}; void (^blk)(void) = ^{ NSLog(@"aaaaa"); }; //调用 blk(); //定义和调用一起 int aa = ^(NSString *var){ NSLog(@"sssss %@",var); return 88; }(@"trrrr"); NSLog(@"aaa = %d",aa); int (^blk1)(void) = ^{ NSLog(@"bbbbb"); return 88888; }; //作为参数,先定义 foo(blk1); //作为参数,不先定义,直接写 foo(^{NSLog(@"ddddd");return 9999;}); } int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); //function_1(29,22.3); run(); } return 0; }