From f83abb578a4dc1c8f523368a089148ca7133d002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E5=8D=9A?= Date: Fri, 6 Mar 2015 16:37:38 +0800 Subject: [PATCH] Use __typeof(self) when assigning weak reference for block. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 庞博 --- SDWebImage/MKAnnotationView+WebCache.m | 2 +- SDWebImage/SDWebImageDownloader.m | 2 +- SDWebImage/UIButton+WebCache.m | 4 ++-- SDWebImage/UIImageView+HighlightedWebCache.m | 2 +- SDWebImage/UIImageView+WebCache.m | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index 62b48a36c..0f6d9ee90 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -45,7 +45,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder self.image = placeholder; if (url) { - __weak MKAnnotationView *wself = self; + __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe(^{ diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index aa3f1cbc1..3e486eaf8 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -113,7 +113,7 @@ - (void)setOperationClass:(Class)operationClass { - (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { __block SDWebImageDownloaderOperation *operation; - __weak SDWebImageDownloader *wself = self; + __weak __typeof(self)wself = self; [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{ NSTimeInterval timeoutInterval = wself.downloadTimeout; diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index ff26732b9..ee2e7e410 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -68,7 +68,7 @@ - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placehold self.imageURLStorage[@(state)] = url; - __weak UIButton *wself = self; + __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe(^{ @@ -111,7 +111,7 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state [self setBackgroundImage:placeholder forState:state]; if (url) { - __weak UIButton *wself = self; + __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe(^{ diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index bc76d7a28..2f4e38b1a 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -33,7 +33,7 @@ - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)op [self sd_cancelCurrentHighlightedImageLoad]; if (url) { - __weak UIImageView *wself = self; + __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe (^ diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 440613be2..fdb351bea 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -49,7 +49,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } if (url) { - __weak UIImageView *wself = self; + __weak __typeof(self)wself = self; id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe(^{ @@ -92,7 +92,7 @@ - (NSURL *)sd_imageURL { - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { [self sd_cancelCurrentAnimationImagesLoad]; - __weak UIImageView *wself = self; + __weak __typeof(self)wself = self; NSMutableArray *operationsArray = [[NSMutableArray alloc] init];