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