Do I need to use the weak self in blocks in Objective-C?

I noticed Apple documentation saying that we need to avoid strong reference loops when capturing ourselves.

The block in the example is a self property.

But what if I put the block as a local variable in the dispatch_async statement?

In this case, it will not create a save loop, even if I directly call the self method, right?

Is the following code generating weakSelf required in this article ?

// your code
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (strongSelf) {
        [strongSelf doThis];
        [strongSelf doThat];
        [Manager.sharedInstance updateSuccessCount];
    }
});

// more code
+4
source share
1 answer

dispatch_async , self. , self , dispatch_async, , self . , dispatch_async.

, , , , , , - , , , , , , self .

, self , - . .

+5

All Articles