Use __typeof(self) when assigning weak reference for block.
Signed-off-by: 庞博 <bopang@sohu-inc.com>
Showing
5 changed files
with
7 additions
and
7 deletions
@@ -45,7 +45,7 @@ static char imageURLKey; | @@ -45,7 +45,7 @@ static char imageURLKey; | ||
45 | self.image = placeholder; | 45 | self.image = placeholder; |
46 | 46 | ||
47 | if (url) { | 47 | if (url) { |
48 | - __weak MKAnnotationView *wself = self; | 48 | + __weak __typeof(self)wself = self; |
49 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 49 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
50 | if (!wself) return; | 50 | if (!wself) return; |
51 | dispatch_main_sync_safe(^{ | 51 | dispatch_main_sync_safe(^{ |
@@ -113,7 +113,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; | @@ -113,7 +113,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; | ||
113 | 113 | ||
114 | - (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { | 114 | - (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { |
115 | __block SDWebImageDownloaderOperation *operation; | 115 | __block SDWebImageDownloaderOperation *operation; |
116 | - __weak SDWebImageDownloader *wself = self; | 116 | + __weak __typeof(self)wself = self; |
117 | 117 | ||
118 | [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{ | 118 | [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{ |
119 | NSTimeInterval timeoutInterval = wself.downloadTimeout; | 119 | NSTimeInterval timeoutInterval = wself.downloadTimeout; |
@@ -68,7 +68,7 @@ static char imageURLStorageKey; | @@ -68,7 +68,7 @@ static char imageURLStorageKey; | ||
68 | 68 | ||
69 | self.imageURLStorage[@(state)] = url; | 69 | self.imageURLStorage[@(state)] = url; |
70 | 70 | ||
71 | - __weak UIButton *wself = self; | 71 | + __weak __typeof(self)wself = self; |
72 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 72 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
73 | if (!wself) return; | 73 | if (!wself) return; |
74 | dispatch_main_sync_safe(^{ | 74 | dispatch_main_sync_safe(^{ |
@@ -111,7 +111,7 @@ static char imageURLStorageKey; | @@ -111,7 +111,7 @@ static char imageURLStorageKey; | ||
111 | [self setBackgroundImage:placeholder forState:state]; | 111 | [self setBackgroundImage:placeholder forState:state]; |
112 | 112 | ||
113 | if (url) { | 113 | if (url) { |
114 | - __weak UIButton *wself = self; | 114 | + __weak __typeof(self)wself = self; |
115 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 115 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
116 | if (!wself) return; | 116 | if (!wself) return; |
117 | dispatch_main_sync_safe(^{ | 117 | dispatch_main_sync_safe(^{ |
@@ -33,7 +33,7 @@ | @@ -33,7 +33,7 @@ | ||
33 | [self sd_cancelCurrentHighlightedImageLoad]; | 33 | [self sd_cancelCurrentHighlightedImageLoad]; |
34 | 34 | ||
35 | if (url) { | 35 | if (url) { |
36 | - __weak UIImageView *wself = self; | 36 | + __weak __typeof(self)wself = self; |
37 | id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 37 | id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
38 | if (!wself) return; | 38 | if (!wself) return; |
39 | dispatch_main_sync_safe (^ | 39 | dispatch_main_sync_safe (^ |
@@ -49,7 +49,7 @@ static char imageURLKey; | @@ -49,7 +49,7 @@ static char imageURLKey; | ||
49 | } | 49 | } |
50 | 50 | ||
51 | if (url) { | 51 | if (url) { |
52 | - __weak UIImageView *wself = self; | 52 | + __weak __typeof(self)wself = self; |
53 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 53 | id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
54 | if (!wself) return; | 54 | if (!wself) return; |
55 | dispatch_main_sync_safe(^{ | 55 | dispatch_main_sync_safe(^{ |
@@ -92,7 +92,7 @@ static char imageURLKey; | @@ -92,7 +92,7 @@ static char imageURLKey; | ||
92 | 92 | ||
93 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { | 93 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { |
94 | [self sd_cancelCurrentAnimationImagesLoad]; | 94 | [self sd_cancelCurrentAnimationImagesLoad]; |
95 | - __weak UIImageView *wself = self; | 95 | + __weak __typeof(self)wself = self; |
96 | 96 | ||
97 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; | 97 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; |
98 | 98 |
-
Please register or login to post a comment