Block Code blocks Analysis

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.