When I reading SDWebImage source code, I found a snippet
if (url)
{
__weak UIButton *wself = self;
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
__strong UIButton *sself = wself;
if (!sself) return;
if (image)
{
[sself setBackgroundImage:image forState:state];
}
if (completedBlock && finished)
{
completedBlock(image, error, cacheType);
}
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
It is easy to understand that for avoiding the retain cycle, it uses __weak keyword for the self, however, why it assigns wself to a strong variable sself, won't the block be still retain the self.