Code block (block) function Body (ii)

Source: Internet
Author: User

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)

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.