iOS Learning Path--block

Source: Internet
Author: User

/*1. Define the BLOCK variable: return value type (^block variable name) (parameter type 1, parameter Type 2, ...); 2. Assign the block variable The block variable name = ^ (parameter type 1 parameter name 1, ...) {     }; *//*1. Set animation Properties 2. Start the animation 3. Animation execution Complete Block1 = ^{encapsulates what you want to do before the animation starts executing}; Block2 = ^{encapsulates what you want to do after the animation is executed}; */#import<Foundation/Foundation.h>//typedef int MYINT;//Myblock is actually the new data type nametypedefint(^myblock) (int,int);/*need to Master: 1. Define the block variable 2. Assigning block variables to 3.type and block applications*/intMainintargcConst Char*argv[]) {Myblock minus= ^(intAintb) {returnAb;    }; intD = Minus (Ten,5); NSLog (@"D ID%d", D); Myblock sum= ^(intV1,intv2) {        returnV1 +v2;        }; intE = SUM (Ten, One); NSLog (@"E is%d", E); /*Int (^minusblock) (int, int) = ^ (int A, int.) {return a-B;    };            Minusblock (10, 5);    Int (^averageblock) (int, int) = ^ (int a, int b) {return (A + b)/2; };*/            return 0;}voidtest2 () {intA =Ten; __blockintb =Ten; //The default local variables cannot be modified inside the block//define a block variable    void(^block) () = ^{        //a = one;b = One; NSLog (@"b=%d", B);        };    Block ();    Block (); Block ();}voidTest () {//the Void:block on the left has no return value//rightmost (): No parameters//The symbol of the middle (^) block, cannot be less    void(^myblock) ()  = ^{        intA = One; intb = One; NSLog (@"a=%d, b=%d", A, b);    };        Myblock (); //define a block variable with a variable name of Sumblock//The return value of the leftmost int:block is of type int//The rightmost (int, int) block accepts two parameters of type int    int(^sumblock) (int,int); Sumblock= ^(intV1,intv2) {        returnV1 +v2;        }; intsum = Sumblock (Ten, One); NSLog (@"sum=%d", sum);}

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.