The data stored by the code block is a function body. With code blocks, you can pass in the number of arguments as you would call other standard functions, and get the return value.
//block as a parameter of a function//function return value type function name (block declaration format)voidFunint(^block) (intAintb)) { intSum=block (5,6); NSLog (@"%d", sum);}voidFUN1 (NSString * (^myblock) (NSString *s), NSString *S1) {NSLog (@"%@", Myblock (S1));}intMainintargcConst Char*argv[]) {@autoreleasepool {//when a block is used as a function parameter, its return value type, number of parameters, and type are consistent with the function parameter format. int(^myblock) (intAintb) =^ (intAintb) {NSLog (@"%d,%d", A, b); returnA *b; }; //The function parameter is block, and when called, the name of the block is directly passed .Fun (Myblock); //another way to invoke: inline//Inline block Format: ^ return value type (formal parameter list) {}Fun (^int(intAintb) {returnA-b; }); FUN1 (^nsstring * (NSString *s) {returns; }, @"123"); } return 0;}
Code block (block) function Body (ii)