Part of Block (code block) easy to understand (i)

Source: Internet
Author: User

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)

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.