A simple understanding of the code
#import <Foundation/Foundation.h>intC=0;intMainintargcConst Char*argv[]) {@autoreleasepool {//Block declaration format: return value type (^block name) (formal parameter list) int(^myfun) (); //Block implementation: Block name =^ (formal parameter list) {};myfun=^() {NSLog (@"This is a block of code"); return 1; }; //Call: Block name (argument list), block with return value, can be received with a variable intA=myfun (); NSLog (@"%d", a); //There are return values, tangible parameters, declarations and implementations put together int(^myblock) (intAintb) =^ (intAintb) { returnA +b; }; //called intSum=myblock (Ten, -); NSLog (@"%d", sum); //The return type is a string NSString * (^ name) (formal parameter list)NSString * (^MYBLOCK1) (NSString *s) =^ (NSString *s) {NSLog (@"string%@", s); returns; }; MyBlock1 (@"456"); //There is a local variable that is going to change the value of the block__blockintb=0; void(^MYBLOCK2) ()=^() {b++; NSLog (@"%d", B); }; //There is a global variable that changes the value of the block void(^MYBLOCK3) ()=^() {c++; };//For example//declares a square block Pointer that points to a block with an int input and an int output int(^square) (int); //Assigning a block entity to squareSquare = ^ (intA) {returnA +A;}; //invokes a method. inty = Square (6); NSLog (@"%d", y); } return 0;}
Part of Block (code block) easy to understand (i)