From 3d1d9f2506b4f67315d0fc9eeadf66ae0f9ee325 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 15 Jan 2018 20:18:01 +0800 Subject: [PATCH] Fix the issue that `setAnimationImagesWithURLs` weak reference may dealloc before the animated images was set --- SDWebImage/UIImageView+WebCache.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index b25a234f..aa8ce431 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -71,15 +71,14 @@ - (void)sd_setAnimationImagesWithURLs:(nonnull NSArray *)arrayOfURLs { [self sd_cancelCurrentAnimationImagesLoad]; - __weak __typeof(self)wself = self; - NSPointerArray *operationsArray = [self sd_animationOperationArray]; - + [arrayOfURLs enumerateObjectsUsingBlock:^(NSURL *logoImageURL, NSUInteger idx, BOOL * _Nonnull stop) { + __weak __typeof(self) wself = self; id operation = [[SDWebImageManager sharedManager] loadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { - if (!wself) return; + __strong typeof(wself) sself = wself; + if (!sself) return; dispatch_main_async_safe(^{ - __strong UIImageView *sself = wself; [sself stopAnimating]; if (sself && image) { NSMutableArray *currentImages = [[sself animationImages] mutableCopy];