diff --git a/SDWebImage/MapKit/MKAnnotationView+WebCache.m b/SDWebImage/MapKit/MKAnnotationView+WebCache.m index a6721a9e..fed23675 100644 --- a/SDWebImage/MapKit/MKAnnotationView+WebCache.m +++ b/SDWebImage/MapKit/MKAnnotationView+WebCache.m @@ -54,13 +54,14 @@ context:(nullable SDWebImageContext *)context progress:(nullable SDImageLoaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock { - __weak typeof(self)weakSelf = self; + @weakify(self); [self sd_internalSetImageWithURL:url placeholderImage:placeholder options:options context:context setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - weakSelf.image = image; + @strongify(self); + self.image = image; } progress:progressBlock completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { diff --git a/SDWebImage/NSButton+WebCache.m b/SDWebImage/NSButton+WebCache.m index 74383054..8800cea5 100644 --- a/SDWebImage/NSButton+WebCache.m +++ b/SDWebImage/NSButton+WebCache.m @@ -121,13 +121,14 @@ static NSString * const SDAlternateImageOperationKey = @"NSButtonAlternateImageO mutableContext = [NSMutableDictionary dictionary]; } mutableContext[SDWebImageContextSetImageOperationKey] = SDAlternateImageOperationKey; - __weak typeof(self)weakSelf = self; + @weakify(self); [self sd_internalSetImageWithURL:url placeholderImage:placeholder options:options context:mutableContext setImageBlock:^(NSImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - weakSelf.alternateImage = image; + @strongify(self); + self.alternateImage = image; } progress:progressBlock completed:^(NSImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 54034780..e31ba9b5 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -104,13 +104,14 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat mutableContext = [NSMutableDictionary dictionary]; } mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state); - __weak typeof(self)weakSelf = self; + @weakify(self); [self sd_internalSetImageWithURL:url placeholderImage:placeholder options:options context:mutableContext setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - [weakSelf setImage:image forState:state]; + @strongify(self); + [self setImage:image forState:state]; } progress:progressBlock completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { @@ -188,13 +189,14 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat mutableContext = [NSMutableDictionary dictionary]; } mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state); - __weak typeof(self)weakSelf = self; + @weakify(self); [self sd_internalSetImageWithURL:url placeholderImage:placeholder options:options context:mutableContext setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - [weakSelf setBackgroundImage:image forState:state]; + @strongify(self); + [self setBackgroundImage:image forState:state]; } progress:progressBlock completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 6560f46f..c2b4dcaa 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -46,7 +46,7 @@ static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOpera context:(nullable SDWebImageContext *)context progress:(nullable SDImageLoaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock { - __weak typeof(self)weakSelf = self; + @weakify(self); SDWebImageMutableContext *mutableContext; if (context) { mutableContext = [context mutableCopy]; @@ -59,7 +59,8 @@ static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOpera options:options context:mutableContext setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - weakSelf.highlightedImage = image; + @strongify(self); + self.highlightedImage = image; } progress:progressBlock completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {