Weak in blocks

The question arises about the weak self, blocks and saves the cycle.

In the book, I understand that we need to use weakly in blocks. The question is when?

for example, simple animation code, never contains weaknesses.

i.e

self.myView.alpha = 1.0;
[UIView animateWithDuration:0.2 animations:^{
self.myView.alpha = 1.0; 
}];

is this code ok? or should I create a weakness in front of the block and use it inside?

In all my code and in all other projects that I have ever worked on, I have never seen a single line that uses a weak me. Now I am trying to use weakness in every block. it's just that I'm not sure it is necessary

Waiting for your feedback. Thanks.

+4
source share
2 answers

, weakSelf , (, ). weakSelf, , ( , ).

, . , . , , , , . , , , , , .

, weakSelf , , , , . , weakSelf .

animateWithDuration, , , .

+4

selfs, .

, foo bar. foo self. - foo, . foo bar bar, foo . Foo , , , bar, . , , - foo. , , .

UIView , animate:, UIView .

ARC , . . , , , .

, .

+7

Source: https://habr.com/ru/post/1534833/


All Articles