Summary of block learning (personal summary)

Source: Internet
Author: User

I have previously written something about block ~ However, it is too complicated and cumbersome, so I will write a summary post today.

1. How to declare a block

Block Declaration has two forms, which are very important and confusing.

The first is to directly declare the block variable.

INT (^ bblock) (int A, int B) bblock is the function name. It is declared in other forms and cannot be found online.

The second is to declare the block variable as a parameter, which is different from directly declaring the block variable.

(Void) testf: bool (^) (int A, int B) bblock; bool (^) (int A, int B) bblock is the declaration of the parameter block

 

If the block statement in the preceding two methods is not understood, you can leave a message. You can also send my email address [email protected]

In this way, block is almost the same, but there is a very important problem left over. I just discovered that I directly excerpted others' blogs, because he wrote it clearly.

 

In a block, using self or a member variable of the class will increase the reference count of self by 1, leading to loop reference, and the current self cannot be released.

Mmatchhead is a custom view pasted in VC and uses two blocks for callback.

In withminutefinish: there are two problems in this block, resulting in circular reference.

 

The first one is self. It is wrong to directly use self in the block.

Second, currentscore is used. This member variable, even if self. XX is not added, will cause the self reference count to be added 1.

Therefore, the solution is,

Use the _ Block Variable of bself instead. Compare the two online images. Self and currentscore.

 

As for the second method written in this blog post, I think it is of little use and I will not add it. I can check it myself.

Http://hi.baidu.com/apple_xingpppp/item/8debb830970c136a7d034b72

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.