iOS Development--Grammar OC Chapter &block Review

Source: Internet
Author: User

Block review

Here is a brief introduction to the syntax of block, if you think it is very simple or want to learn more in-depth use of inventory to see the reporter before the use of block values and advanced block use:

Http://www.cnblogs.com/iCocos/p/4534281.html

Http://www.cnblogs.com/iCocos/p/4550169.html

Http://www.cnblogs.com/iCocos/p/4659878.html

Http://www.cnblogs.com/iCocos/p/4655846.html

    • Block:block function, code block
    • Block is a "special" object

Function:

    • 1. No return value no parameters
    • 2. No return value has parameters
    • 3. There are parameters to return

Block:

    • 1. No return value no parameters
    • 2. No return value has parameters
    • 3. There are parameters to return

No return value no parameter

C Language Functions:

1 // No return value no parameter function 2 void say1 () {3     NSLog (@ "say1 ... " ); 4 }
    // calling Functions     say1 ();    


OC code block:

1 //1. No return value no parameter block2 3 voidtest1 () {4 5     //1. No return value no parameter block6 7     void(^say1block) () = ^{8 9NSLog (@"Say1block ...");Ten  One     }; A  -     //Call Block -  the Say1block (); -  -}

No return value has parameters

C Language Functions:

1 // no return value with parametric function 2 3 void say2 (int age ) {45     NSLog (@ "I ' am%d year old! " , age); 6 7 }
        // called    Say2 ();

OC code block:

1 //2. No return value with parameter block2 3 voidtest2 () {4 5 6     void(^say2block) (int) = ^(intAge ) {7 8NSLog (@"I ' am%d year old!", age);9 Ten     }; One  A  -Say2block ( -); -  the   -  -}

There are return values with parameters

C language functions:

1 // There are return values with parametric functions 2 3 int sum (int A,int  b) {45     return a + b; 6 7 }89  

OC code block:

1 //3. There is a return parameter block2 3 voidtest3 () {4 5       int(^sumblock) (int,int) = ^(intAintb) {6 7             returnA +b;8 9         };Ten  One         intRESULT1 = SUM (Ten,Ten); A  -         intRESULT2 = Sumblock ( One, One); -  theNSLog (@"result1:%d result2:%d", RESULT1,RESULT2); -  -          -  +         //typedef a block -  +   A  at         //Redefine "No return value" without parameter Block -  -typedefvoid(^Say2block) (); -  -          -  inSay2block block = ^{ -  toNSLog (@"Say2block ========"); +  -         }; the  *          $ Panax Notoginseng block (); -  the}

iOS Development--Grammar OC Chapter &block Review

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.