Merge pull request #2651 from Insofan/5.x

Clean some code to weakify && strongify macros which is depened on  pr #2647
This commit is contained in:
DreamPiggy 2019-03-26 17:38:02 +08:00 committed by GitHub
commit bdd4667f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View File

@ -54,13 +54,14 @@
context:(nullable SDWebImageContext *)context context:(nullable SDWebImageContext *)context
progress:(nullable SDImageLoaderProgressBlock)progressBlock progress:(nullable SDImageLoaderProgressBlock)progressBlock
completed:(nullable SDExternalCompletionBlock)completedBlock { completed:(nullable SDExternalCompletionBlock)completedBlock {
__weak typeof(self)weakSelf = self; @weakify(self);
[self sd_internalSetImageWithURL:url [self sd_internalSetImageWithURL:url
placeholderImage:placeholder placeholderImage:placeholder
options:options options:options
context:context context:context
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
weakSelf.image = image; @strongify(self);
self.image = image;
} }
progress:progressBlock progress:progressBlock
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {

View File

@ -121,13 +121,14 @@ static NSString * const SDAlternateImageOperationKey = @"NSButtonAlternateImageO
mutableContext = [NSMutableDictionary dictionary]; mutableContext = [NSMutableDictionary dictionary];
} }
mutableContext[SDWebImageContextSetImageOperationKey] = SDAlternateImageOperationKey; mutableContext[SDWebImageContextSetImageOperationKey] = SDAlternateImageOperationKey;
__weak typeof(self)weakSelf = self; @weakify(self);
[self sd_internalSetImageWithURL:url [self sd_internalSetImageWithURL:url
placeholderImage:placeholder placeholderImage:placeholder
options:options options:options
context:mutableContext context:mutableContext
setImageBlock:^(NSImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { setImageBlock:^(NSImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
weakSelf.alternateImage = image; @strongify(self);
self.alternateImage = image;
} }
progress:progressBlock progress:progressBlock
completed:^(NSImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { completed:^(NSImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {

View File

@ -104,13 +104,14 @@ static inline NSString * backgroundImageOperationKeyForState(UIControlState stat
mutableContext = [NSMutableDictionary dictionary]; mutableContext = [NSMutableDictionary dictionary];
} }
mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state); mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state);
__weak typeof(self)weakSelf = self; @weakify(self);
[self sd_internalSetImageWithURL:url [self sd_internalSetImageWithURL:url
placeholderImage:placeholder placeholderImage:placeholder
options:options options:options
context:mutableContext context:mutableContext
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { 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 progress:progressBlock
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { 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 = [NSMutableDictionary dictionary];
} }
mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state); mutableContext[SDWebImageContextSetImageOperationKey] = imageOperationKeyForState(state);
__weak typeof(self)weakSelf = self; @weakify(self);
[self sd_internalSetImageWithURL:url [self sd_internalSetImageWithURL:url
placeholderImage:placeholder placeholderImage:placeholder
options:options options:options
context:mutableContext context:mutableContext
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { 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 progress:progressBlock
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {

View File

@ -46,7 +46,7 @@ static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOpera
context:(nullable SDWebImageContext *)context context:(nullable SDWebImageContext *)context
progress:(nullable SDImageLoaderProgressBlock)progressBlock progress:(nullable SDImageLoaderProgressBlock)progressBlock
completed:(nullable SDExternalCompletionBlock)completedBlock { completed:(nullable SDExternalCompletionBlock)completedBlock {
__weak typeof(self)weakSelf = self; @weakify(self);
SDWebImageMutableContext *mutableContext; SDWebImageMutableContext *mutableContext;
if (context) { if (context) {
mutableContext = [context mutableCopy]; mutableContext = [context mutableCopy];
@ -59,7 +59,8 @@ static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOpera
options:options options:options
context:mutableContext context:mutableContext
setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
weakSelf.highlightedImage = image; @strongify(self);
self.highlightedImage = image;
} }
progress:progressBlock progress:progressBlock
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {