Use of block in OC

Source: Internet
Author: User

Block is a data type used to hold a piece of code

Defines a pointer to a function very much like

Int (*MYP) (Int,int) {

}

typedef int (*MYP) (int,int);

Block Flag ^

Block is like a function.

L can save the code

L have return value

L Tangible parameters

L Call the same way

Attention

L default block cannot modify external local variables

L can modify local variables in block code after adding _block to local variables.

1. Define a block type

return value type (^block type name) (parameter type,.....)

Int (^MYB) (int,int); /int (^MYB) ();

2. Assigning a value to a defined type

MyB = ^ (int a, int b)

{

}

MyB = ^{

}

1, 2 together is

Int (^myblock) (int,int) = ^ (int a,int b) {

};

typedif Int (^MYB) (int, int);

Use of block in OC

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.