Skip to content

Commit

Permalink
Use __typeof(self) when assigning weak reference for block.
Browse files Browse the repository at this point in the history
Signed-off-by: 庞博 <[email protected]>
  • Loading branch information
庞博 committed Mar 6, 2015
1 parent 9cc8269 commit f83abb5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SDWebImage/MKAnnotationView+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SDWebImageOperation> 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(^{
Expand Down
2 changes: 1 addition & 1 deletion SDWebImage/SDWebImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ - (void)setOperationClass:(Class)operationClass {

- (id <SDWebImageOperation>)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;
Expand Down
4 changes: 2 additions & 2 deletions SDWebImage/UIButton+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SDWebImageOperation> 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(^{
Expand Down Expand Up @@ -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 <SDWebImageOperation> 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(^{
Expand Down
2 changes: 1 addition & 1 deletion SDWebImage/UIImageView+HighlightedWebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<SDWebImageOperation> 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 (^
Expand Down
4 changes: 2 additions & 2 deletions SDWebImage/UIImageView+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
}

if (url) {
__weak UIImageView *wself = self;
__weak __typeof(self)wself = self;
id <SDWebImageOperation> 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(^{
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit f83abb5

Please sign in to comment.