1, block in the program run to save a piece of code
Block flag: ^
Can save code, have return value, tangible parameter
2. Define the block variable
Int (^sumblock) (int, int);
3, block by default can access the outside variables, can not modify the outside local variables
Add the _block keyword to the local variable and the local variable can be modified inside the block
4.
Block with no formal parameter and no return value
void (^myblock) () = ^{
NSLog (@ "block with no return value");
};
When the block is called, it executes, calling method: Myblock ();
Block with a return value and a tangible parameter
Int (^sumblock) (int, int) = ^ (int a, int b) {
return a + B;
};
Calling methods
int c = Sumblock (10, 20);
Defining block types with typedef
typedef int (^myblock) (int, int);//myblock is a type
Myblock Sumblock = ^ (int a, int b) {
return a + B;
};
Block Code blocks Analysis