diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index 2f9a8f77d..5bec61197 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -20,7 +20,7 @@ * Note that because of the limitations of categories this property can get out of sync * if you use sd_setImage: directly. */ -- (NSURL *)imageURL; +- (NSURL *)sd_imageURL; /** * Set the imageView `image` with an `url`. @@ -102,13 +102,15 @@ /** * Cancel the current download */ -- (void)cancelCurrentImageLoad; +- (void)sd_cancelCurrentImageLoad; @end @interface MKAnnotationView (WebCacheDeprecated) +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); + - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`"); @@ -117,4 +119,6 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); + @end diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index b1d62421c..240f5af76 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -8,13 +8,13 @@ #import "MKAnnotationView+WebCache.h" #import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" static char imageURLKey; -static char operationKey; @implementation MKAnnotationView (WebCache) -- (NSURL *)imageURL { +- (NSURL *)sd_imageURL { return objc_getAssociatedObject(self, &imageURLKey); } @@ -59,7 +59,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } }); }]; - objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"]; } else { dispatch_main_async_safe(^{ NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; @@ -70,13 +70,8 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } } -- (void)cancelCurrentImageLoad { - // Cancel in progress downloader from queue - id operation = objc_getAssociatedObject(self, &operationKey); - if (operation) { - [operation cancel]; - objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } +- (void)sd_cancelCurrentImageLoad { + [self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"]; } @end @@ -84,6 +79,10 @@ - (void)cancelCurrentImageLoad { @implementation MKAnnotationView (WebCacheDeprecated) +- (NSURL *)imageURL { + return [self sd_imageURL]; +} + - (void)setImageWithURL:(NSURL *)url { [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; } @@ -120,4 +119,8 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder opt }]; } +- (void)cancelCurrentImageLoad { + [self sd_cancelCurrentImageLoad]; +} + @end diff --git a/SDWebImage/NSData+ImageContentType.h b/SDWebImage/NSData+ImageContentType.h index 9ad2dfe89..69c76dc77 100644 --- a/SDWebImage/NSData+ImageContentType.h +++ b/SDWebImage/NSData+ImageContentType.h @@ -14,6 +14,13 @@ * * @return the content type as string (i.e. image/jpeg, image/gif) */ -+ (NSString *)contentTypeForImageData:(NSData *)data; ++ (NSString *)sd_contentTypeForImageData:(NSData *)data; + +@end + + +@interface NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); @end diff --git a/SDWebImage/NSData+ImageContentType.m b/SDWebImage/NSData+ImageContentType.m index 6fb352d85..0941cfaa0 100644 --- a/SDWebImage/NSData+ImageContentType.m +++ b/SDWebImage/NSData+ImageContentType.m @@ -8,7 +8,7 @@ @implementation NSData (ImageContentType) -+ (NSString *)contentTypeForImageData:(NSData *)data { ++ (NSString *)sd_contentTypeForImageData:(NSData *)data { uint8_t c; [data getBytes:&c length:1]; switch (c) { @@ -38,3 +38,12 @@ + (NSString *)contentTypeForImageData:(NSData *)data { } @end + + +@implementation NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data { + return [self sd_contentTypeForImageData:data]; +} + +@end diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index 6830d4fe2..7a6e867f4 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -17,14 +17,14 @@ /** * Get the current image URL. */ -- (NSURL *)currentImageURL; +- (NSURL *)sd_currentImageURL; /** * Get the image URL for a control state. * * @param state Which state you want to know the URL for. The values are described in UIControlState. */ -- (NSURL *)imageURLForState:(UIControlState)state; +- (NSURL *)sd_imageURLForState:(UIControlState)state; /** * Set the imageView `image` with an `url`. @@ -192,18 +192,21 @@ /** * Cancel the current image download */ -- (void)cancelImageLoadForState:(UIControlState)state; +- (void)sd_cancelImageLoadForState:(UIControlState)state; /** * Cancel the current backgroundImage download */ -- (void)cancelBackgroundImageLoadForState:(UIControlState)state; +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state; @end @interface UIButton (WebCacheDeprecated) +- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`"); +- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`"); + - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`"); - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`"); - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`"); @@ -220,6 +223,7 @@ - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`"); - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); -- (void)cancelCurrentImageLoad __deprecated_msg("Use `cancelImageLoadForState:`"); +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`"); +- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`"); @end diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 257f78cfe..8e076ae56 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -8,13 +8,13 @@ #import "UIButton+WebCache.h" #import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" static char imageURLStorageKey; -static char operationKey; @implementation UIButton (WebCache) -- (NSURL *)currentImageURL { +- (NSURL *)sd_currentImageURL { NSURL *url = self.imageURLStorage[@(self.state)]; if (!url) { @@ -24,7 +24,7 @@ - (NSURL *)currentImageURL { return url; } -- (NSURL *)imageURLForState:(UIControlState)state { +- (NSURL *)sd_imageURLForState:(UIControlState)state { return self.imageURLStorage[@(state)]; } @@ -51,7 +51,7 @@ - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placehold - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self setImage:placeholder forState:state]; - [self cancelCurrentImageLoad]; + [self sd_cancelImageLoadForState:state]; if (!url) { [self.imageURLStorage removeObjectForKey:@(state)]; @@ -82,7 +82,7 @@ - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placehold } }); }]; - objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setImageLoadOperation:operation forState:state]; } - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { @@ -106,7 +106,7 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state } - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { - [self cancelCurrentImageLoad]; + [self sd_cancelImageLoadForState:state]; [self setBackgroundImage:placeholder forState:state]; @@ -125,7 +125,7 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state } }); }]; - objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setBackgroundImageLoadOperation:operation forState:state]; } else { dispatch_main_async_safe(^{ NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; @@ -136,14 +136,20 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state } } +- (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} -- (void)cancelCurrentImageLoad { - // Cancel in progress downloader from queue - id operation = objc_getAssociatedObject(self, &operationKey); - if (operation) { - [operation cancel]; - objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } +- (void)sd_cancelImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} + +- (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; +} + +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; } - (NSMutableDictionary *)imageURLStorage { @@ -162,6 +168,14 @@ - (NSMutableDictionary *)imageURLStorage { @implementation UIButton (WebCacheDeprecated) +- (NSURL *)currentImageURL { + return [self sd_currentImageURL]; +} + +- (NSURL *)imageURLForState:(UIControlState)state { + return [self sd_imageURLForState:state]; +} + - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } @@ -236,7 +250,11 @@ - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state pl - (void)cancelCurrentImageLoad { // in a backwards compatible manner, cancel for current state - [self cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(self.state)]]; + [self sd_cancelImageLoadForState:self.state]; +} + +- (void)cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelBackgroundImageLoadForState:state]; } @end diff --git a/SDWebImage/UIImage+GIF.m b/SDWebImage/UIImage+GIF.m index f48d179f7..a7036372a 100755 --- a/SDWebImage/UIImage+GIF.m +++ b/SDWebImage/UIImage+GIF.m @@ -33,7 +33,7 @@ + (UIImage *)sd_animatedGIFWithData:(NSData *)data { for (size_t i = 0; i < count; i++) { CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); - duration += [self frameDurationAtIndex:i source:source]; + duration += [self sd_frameDurationAtIndex:i source:source]; [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; @@ -52,7 +52,7 @@ + (UIImage *)sd_animatedGIFWithData:(NSData *)data { return animatedImage; } -+ (float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { ++ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { float frameDuration = 0.1f; CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; diff --git a/SDWebImage/UIImage+MultiFormat.m b/SDWebImage/UIImage+MultiFormat.m index 90f55628f..a0b138cbd 100644 --- a/SDWebImage/UIImage+MultiFormat.m +++ b/SDWebImage/UIImage+MultiFormat.m @@ -19,7 +19,7 @@ @implementation UIImage (MultiFormat) + (UIImage *)sd_imageWithData:(NSData *)data { UIImage *image; - NSString *imageContentType = [NSData contentTypeForImageData:data]; + NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; if ([imageContentType isEqualToString:@"image/gif"]) { image = [UIImage sd_animatedGIFWithData:data]; } diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index 68b644983..6b0036635 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -7,7 +7,8 @@ */ #import -#import "UIImageView+WebCache.h" +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" /** * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state. @@ -78,6 +79,11 @@ */ - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; +/** + * Cancel the current download + */ +- (void)sd_cancelCurrentHighlightedImageLoad; + @end @@ -85,9 +91,10 @@ - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`"); - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`"); - - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`"); - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`"); - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`"); +- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`"); + @end diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 07f8d089e..ae73610fa 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -7,9 +7,9 @@ */ #import "UIImageView+HighlightedWebCache.h" -#import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" -static char operationKey; +#define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" @implementation UIImageView (HighlightedWebCache) @@ -30,7 +30,7 @@ - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)op } - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { - [self cancelCurrentImageLoad]; + [self sd_cancelCurrentHighlightedImageLoad]; if (url) { __weak UIImageView *wself = self; @@ -48,7 +48,7 @@ - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)op } }); }]; - objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; } else { dispatch_main_async_safe(^{ NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; @@ -59,6 +59,10 @@ - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)op } } +- (void)sd_cancelCurrentHighlightedImageLoad { + [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; +} + @end @@ -96,4 +100,8 @@ - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)optio }]; } +- (void)cancelCurrentHighlightedImageLoad { + [self sd_cancelCurrentHighlightedImageLoad]; +} + @end diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index ba6e264b8..dc0821920 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -50,7 +50,7 @@ * Note that because of the limitations of categories this property can get out of sync * if you use sd_setImage: directly. */ -- (NSURL *)imageURL; +- (NSURL *)sd_imageURL; /** * Set the imageView `image` with an `url`. @@ -148,22 +148,24 @@ /** * Download an array of images and starts them in an animation loop * - *@param arrayOfURLs An array of NSURL + * @param arrayOfURLs An array of NSURL */ -- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; /** * Cancel the current download */ -- (void)cancelCurrentImageLoad; +- (void)sd_cancelCurrentImageLoad; -- (void)cancelCurrentAnimationImagesLoad; +- (void)sd_cancelCurrentAnimationImagesLoad; @end @interface UIImageView (WebCacheDeprecated) +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); + - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`"); @@ -173,6 +175,10 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`"); -- (void)cancelCurrentArrayLoad __deprecated_msg("Use `cancelCurrentAnimationImagesLoad`"); +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`"); + +- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`"); + +- (void)cancelCurrentImageLoad __deprecated_msg("Use `cancelCurrentImageLoad`"); @end diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 6234f0d9e..b921a32bd 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -8,10 +8,9 @@ #import "UIImageView+WebCache.h" #import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" static char imageURLKey; -static char operationKey; -static char operationArrayKey; @implementation UIImageView (WebCache) @@ -40,7 +39,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { - [self cancelCurrentImageLoad]; + [self sd_cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); if (!(options & SDWebImageDelayPlaceholder)) { @@ -67,7 +66,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } }); }]; - objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; } else { dispatch_main_async_safe(^{ NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; @@ -78,12 +77,12 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder } } -- (NSURL *)imageURL { +- (NSURL *)sd_imageURL { return objc_getAssociatedObject(self, &imageURLKey); } -- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { - [self cancelCurrentArrayLoad]; +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_cancelCurrentAnimationImagesLoad]; __weak UIImageView *wself = self; NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; @@ -110,27 +109,15 @@ - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { [operationsArray addObject:operation]; } - objc_setAssociatedObject(self, &operationArrayKey, [NSArray arrayWithArray:operationsArray], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"]; } -- (void)cancelCurrentImageLoad { - // Cancel in progress downloader from queue - id operation = objc_getAssociatedObject(self, &operationKey); - if (operation) { - [operation cancel]; - objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } +- (void)sd_cancelCurrentImageLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; } -- (void)cancelCurrentArrayLoad { - // Cancel in progress downloader from queue - NSArray *operations = objc_getAssociatedObject(self, &operationArrayKey); - for (id operation in operations) { - if (operation) { - [operation cancel]; - } - } - objc_setAssociatedObject(self, &operationArrayKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +- (void)sd_cancelCurrentAnimationImagesLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; } @end @@ -138,6 +125,10 @@ - (void)cancelCurrentArrayLoad { @implementation UIImageView (WebCacheDeprecated) +- (NSURL *)imageURL { + return [self sd_imageURL]; +} + - (void)setImageWithURL:(NSURL *)url { [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; } @@ -164,7 +155,6 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder com completedBlock(image, error, cacheType); } }]; - } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { @@ -173,7 +163,6 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder opt completedBlock(image, error, cacheType); } }]; - } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { @@ -182,11 +171,18 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder opt completedBlock(image, error, cacheType); } }]; - } - (void)cancelCurrentArrayLoad { - [self cancelCurrentAnimationImagesLoad]; + [self sd_cancelCurrentAnimationImagesLoad]; +} + +- (void)cancelCurrentImageLoad { + [self sd_cancelCurrentImageLoad]; +} + +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_setAnimationImagesWithURLs:arrayOfURLs]; } @end diff --git a/SDWebImage/UIView+WebCacheOperation.h b/SDWebImage/UIView+WebCacheOperation.h index 45d64007b..67190362d 100644 --- a/SDWebImage/UIView+WebCacheOperation.h +++ b/SDWebImage/UIView+WebCacheOperation.h @@ -17,20 +17,20 @@ * @param operation the operation * @param key key for storing the operation */ -- (void)setImageLoadOperation:(id)operation forKey:(NSString *)key; +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; /** * Cancel all operations for the current UIView and key * * @param key key for identifying the operations */ -- (void)cancelImageLoadOperationWithKey:(NSString *)key; +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; /** * Just remove the operations corresponding to the current UIView and key without cancelling them * * @param key key for identifying the operations */ -- (void)removeImageLoadOperationWithKey:(NSString *)key; +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key; @end diff --git a/SDWebImage/UIView+WebCacheOperation.m b/SDWebImage/UIView+WebCacheOperation.m index 64e1ff3e2..92194780d 100644 --- a/SDWebImage/UIView+WebCacheOperation.m +++ b/SDWebImage/UIView+WebCacheOperation.m @@ -23,13 +23,13 @@ - (NSMutableDictionary *)operationDictionary { return operations; } -- (void)setImageLoadOperation:(id)operation forKey:(NSString *)key { - [self cancelImageLoadOperationWithKey:key]; +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { + [self sd_cancelImageLoadOperationWithKey:key]; NSMutableDictionary *operationDictionary = [self operationDictionary]; [operationDictionary setObject:operation forKey:key]; } -- (void)cancelImageLoadOperationWithKey:(NSString *)key { +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { // Cancel in progress downloader from queue NSMutableDictionary *operationDictionary = [self operationDictionary]; id operations = [operationDictionary objectForKey:key]; @@ -47,7 +47,7 @@ - (void)cancelImageLoadOperationWithKey:(NSString *)key { } } -- (void)removeImageLoadOperationWithKey:(NSString *)key { +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key { NSMutableDictionary *operationDictionary = [self operationDictionary]; [operationDictionary removeObjectForKey:key]; }