From a46f6149e502862ef8b8b02a39a8df118dea3f3c Mon Sep 17 00:00:00 2001 From: robertmryan Date: Wed, 11 Jun 2014 02:14:40 -0400 Subject: [PATCH 01/23] Resolve race condition. While exceedingly unlikely, the old construct introduced potential race condition where it checked wself first, and assigned sself second. This now assigns sself first, and then checks that, which is the correct pattern, already used elsewhere in SDWebImage. --- SDWebImage/SDWebImageDownloader.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 09ceb4f9..251bc513 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -127,8 +127,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; NSArray *callbacksForURL = [sself callbacksForURL:url]; for (NSDictionary *callbacks in callbacksForURL) { SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; @@ -136,8 +136,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; } } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; NSArray *callbacksForURL = [sself callbacksForURL:url]; if (finished) { [sself removeCallbacksForURL:url]; @@ -148,8 +148,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; } } cancelled:^{ - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; [sself removeCallbacksForURL:url]; }]; From f63a45add6a4c365fdfad68ff2bef5c5bd5d15a7 Mon Sep 17 00:00:00 2001 From: robertmryan Date: Wed, 11 Jun 2014 02:36:47 -0400 Subject: [PATCH 02/23] Adjusted completion logic in prefetcher, as the old implementation would finish prematurely if any requests were skipped. Also adjusted documentation in headers to make it clear that the `finishedCount` includes both successful and unsuccessful requests. --- SDWebImage/SDWebImagePrefetcher.h | 8 ++++---- SDWebImage/SDWebImagePrefetcher.m | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SDWebImage/SDWebImagePrefetcher.h b/SDWebImage/SDWebImagePrefetcher.h index 991602a5..781635b1 100644 --- a/SDWebImage/SDWebImagePrefetcher.h +++ b/SDWebImage/SDWebImagePrefetcher.h @@ -20,15 +20,15 @@ * * @param imagePrefetcher The current image prefetcher * @param imageURL The image url that was prefetched - * @param finishedCount The total number of images that were prefetched - * @param totalCount The total number of images that need to be prefetched + * @param finishedCount The total number of images that were prefetched (successful or not) + * @param totalCount The total number of images that were to be prefetched */ - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; /** * Called when all images are prefetched. * @param imagePrefetcher The current image prefetcher - * @param totalCount The total number of images that need to be prefetched + * @param totalCount The total number of images that were prefetched (whether successful or not) * @param skippedCount The total number of images that were skipped */ - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; @@ -73,7 +73,7 @@ * and skips images for failed downloads and proceed to the next image in the list * * @param urls list of URLs to prefetch - * @param progressBlock block to be called when progress updates + * @param progressBlock block to be called when progress updates; first parameter is the number of completed (successful or not) requests, second parameter is the total number of images originally requested to be prefetched * @param completionBlock block to be called when prefetching is completed */ - (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock; diff --git a/SDWebImage/SDWebImagePrefetcher.m b/SDWebImage/SDWebImagePrefetcher.m index 74a3bc1e..8c4bc2f9 100644 --- a/SDWebImage/SDWebImagePrefetcher.m +++ b/SDWebImage/SDWebImagePrefetcher.m @@ -88,7 +88,7 @@ [self startPrefetchingAtIndex:self.requestedCount]; }); } - else if (self.finishedCount + self.skippedCount == self.requestedCount) { + else if (self.finishedCount == self.requestedCount) { [self reportStatus]; if (self.completionBlock) { self.completionBlock(self.finishedCount, self.skippedCount); From c76aba6c00077fa6edca7f79477dde38dc736381 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Tue, 17 Jun 2014 22:38:37 +0700 Subject: [PATCH 03/23] support for image orientation --- SDWebImage/UIImage+MultiFormat.m | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/SDWebImage/UIImage+MultiFormat.m b/SDWebImage/UIImage+MultiFormat.m index e2e3e80f..90f55628 100644 --- a/SDWebImage/UIImage+MultiFormat.m +++ b/SDWebImage/UIImage+MultiFormat.m @@ -9,6 +9,7 @@ #import "UIImage+MultiFormat.h" #import "UIImage+GIF.h" #import "NSData+ImageContentType.h" +#import #ifdef SD_WEBP #import "UIImage+WebP.h" @@ -30,10 +31,82 @@ #endif else { image = [[UIImage alloc] initWithData:data]; + UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; + if (orientation != UIImageOrientationUp) { + image = [UIImage imageWithCGImage:image.CGImage + scale:image.scale + orientation:orientation]; + } } return image; } + ++(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { + UIImageOrientation result = UIImageOrientationUp; + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + CFTypeRef val; + int exifOrientation; + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) { + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); + result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; + } // else - if it's not set it remains at up + CFRelease((CFTypeRef) properties); + } else { + //NSLog(@"NO PROPERTIES, FAIL"); + } + CFRelease(imageSource); + return result; +} + +#pragma EXIF orientation tag converter +// Convert an EXIF image orientation to an iOS one. +// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html ++ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { + UIImageOrientation orientation = UIImageOrientationUp; + switch (exifOrientation) { + case 1: + orientation = UIImageOrientationUp; + break; + + case 3: + orientation = UIImageOrientationDown; + break; + + case 8: + orientation = UIImageOrientationLeft; + break; + + case 6: + orientation = UIImageOrientationRight; + break; + + case 2: + orientation = UIImageOrientationUpMirrored; + break; + + case 4: + orientation = UIImageOrientationDownMirrored; + break; + + case 5: + orientation = UIImageOrientationLeftMirrored; + break; + + case 7: + orientation = UIImageOrientationRightMirrored; + break; + default: + break; + } + return orientation; +} + + + @end From e4104942ee13e2ddc0a98fad79636d9061fc5e6e Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Wed, 18 Jun 2014 15:28:13 +0300 Subject: [PATCH 04/23] Return nil from SDScaledImageForKey if the input image is nil. Replaces #750. Fixes #365 --- SDWebImage/SDWebImageCompat.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index 7f911535..8c7d345a 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -13,6 +13,10 @@ #endif inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { + if (!image) { + return nil; + } + if ([image.images count] > 0) { NSMutableArray *scaledImages = [NSMutableArray array]; From e4b9ef512b6de452604484e4eeccbe0aab7db5ef Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Wed, 18 Jun 2014 18:46:50 +0300 Subject: [PATCH 05/23] Fixed a warning in the demo project --- Examples/SDWebImage Demo/MasterViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/SDWebImage Demo/MasterViewController.m b/Examples/SDWebImage Demo/MasterViewController.m index 67951ee8..8300c59f 100644 --- a/Examples/SDWebImage Demo/MasterViewController.m +++ b/Examples/SDWebImage Demo/MasterViewController.m @@ -372,7 +372,7 @@ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } - cell.textLabel.text = [NSString stringWithFormat:@"Image #%d", indexPath.row]; + cell.textLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row]; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; [cell.imageView setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0]; From dfceb49d2ba85c49d89686ab0f5457acc57ac6db Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 10:35:55 +0300 Subject: [PATCH 06/23] Reordered categories in project file --- SDWebImage.xcodeproj/project.pbxproj | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 5fe4baa6..d5e84ef2 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -376,20 +376,20 @@ 53922DA9148C562D0056699D /* Categories */ = { isa = PBXGroup; children = ( - ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */, - ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */, - 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */, - 5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */, - 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */, - 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */, - A18A6CC5172DC28500419892 /* UIImage+GIF.h */, - A18A6CC6172DC28500419892 /* UIImage+GIF.m */, - 53EDFB911762547C00698166 /* UIImage+WebP.h */, - 53EDFB921762547C00698166 /* UIImage+WebP.m */, 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */, 535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */, + 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */, + 5D5B9141188EE8DD006D06BD /* NSData+ImageContentType.m */, 53922D93148C56230056699D /* UIButton+WebCache.h */, 53922D94148C56230056699D /* UIButton+WebCache.m */, + A18A6CC5172DC28500419892 /* UIImage+GIF.h */, + A18A6CC6172DC28500419892 /* UIImage+GIF.m */, + 53EDFB8817623F7C00698166 /* UIImage+MultiFormat.h */, + 53EDFB8917623F7C00698166 /* UIImage+MultiFormat.m */, + 53EDFB911762547C00698166 /* UIImage+WebP.h */, + 53EDFB921762547C00698166 /* UIImage+WebP.m */, + ABBE71A518C43B4D00B75E91 /* UIImageView+HighlightedWebCache.h */, + ABBE71A618C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m */, 53922D95148C56230056699D /* UIImageView+WebCache.h */, 53922D96148C56230056699D /* UIImageView+WebCache.m */, ); From a8f5627052e70052a839c819fef6339a3784e1f5 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 10:36:13 +0300 Subject: [PATCH 07/23] Added doc description for the NSData category --- SDWebImage/NSData+ImageContentType.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SDWebImage/NSData+ImageContentType.h b/SDWebImage/NSData+ImageContentType.h index bb78bb0c..9ad2dfe8 100644 --- a/SDWebImage/NSData+ImageContentType.h +++ b/SDWebImage/NSData+ImageContentType.h @@ -6,5 +6,14 @@ #import @interface NSData (ImageContentType) + +/** + * Compute the content type for an image data + * + * @param data the input data + * + * @return the content type as string (i.e. image/jpeg, image/gif) + */ + (NSString *)contentTypeForImageData:(NSData *)data; + @end From 99b7a090f8782e62a235dbbfd510a9bcbe867892 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 10:51:55 +0300 Subject: [PATCH 08/23] Missing new line --- SDWebImage/UIImageView+HighlightedWebCache.h | 1 + 1 file changed, 1 insertion(+) diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index c82b8bf7..40646ea4 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -22,6 +22,7 @@ * @param url The url for the image. */ - (void)setHighlightedImageWithURL:(NSURL *)url; + /** * Set the imageView `highlightedImage` with an `url` and custom options. * From 233ef65f989185e10c33a79f425a38f905427414 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 11:10:38 +0300 Subject: [PATCH 09/23] Pass image URL in completion blocks - step 1: - deprecated block type `SDWebImageCompletedWithFinishedBlock`, replaced with `SDWebImageCompletionWithFinishedBlock` that contains NSURL* param - deprecated SDWebImageManager `-downloadWithURL:options:progress:completed:` method. Replaced with `downloadImageWithURL:options:progress:completed:` that uses the `SDWebImageCompletionWithFinishedBlock ` as completion block type - created Deprecated category for SDWebImageManager containing the old method - replaced the usages of the deprecated items with the new ones --- SDWebImage/MKAnnotationView+WebCache.m | 2 +- SDWebImage/SDWebImageManager.h | 32 +++++++++++++--- SDWebImage/SDWebImageManager.m | 40 +++++++++++++++----- SDWebImage/SDWebImagePrefetcher.m | 2 +- SDWebImage/UIButton+WebCache.m | 4 +- SDWebImage/UIImageView+HighlightedWebCache.m | 32 +++++++--------- SDWebImage/UIImageView+WebCache.m | 4 +- 7 files changed, 77 insertions(+), 39 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index c4c2f88f..2a29235d 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -48,7 +48,7 @@ static char operationKey; if (url) { __weak MKAnnotationView *wself = self; - id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + 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(^{ __strong MKAnnotationView *sself = wself; diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 6a1a17da..3aa97836 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -79,7 +79,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); -typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished); +typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); @class SDWebImageManager; @@ -126,7 +126,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:imageURL options:0 progress:nil - completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (image) { // do something with image } @@ -188,10 +188,10 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; * * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation */ -- (id )downloadWithURL:(NSURL *)url - options:(SDWebImageOptions)options - progress:(SDWebImageDownloaderProgressBlock)progressBlock - completed:(SDWebImageCompletedWithFinishedBlock)completedBlock; +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock; /** * Saves image to cache for given URL @@ -225,3 +225,23 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; - (NSString *)cacheKeyForURL:(NSURL *)url; @end + + +#pragma mark - Deprecated + +typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); + + +@interface SDWebImageManager (Deprecated) + +/** + * Downloads the image at the given URL if not present in cache or return the cached version otherwise. + * + * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` + */ +- (id )downloadWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); + +@end diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 7c256612..f030a627 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -71,7 +71,10 @@ return [self.imageCache diskImageExistsWithKey:key]; } -- (id )downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock { +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock { // Invoking this method without a completedBlock is pointless NSParameterAssert(completedBlock); @@ -97,7 +100,7 @@ if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { dispatch_main_sync_safe(^{ NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]; - completedBlock(nil, error, SDImageCacheTypeNone, YES); + completedBlock(nil, error, SDImageCacheTypeNone, YES, url); }); return operation; } @@ -121,7 +124,7 @@ dispatch_main_sync_safe(^{ // If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server. - completedBlock(image, nil, cacheType, YES); + completedBlock(image, nil, cacheType, YES, url); }); } @@ -143,12 +146,12 @@ id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) { if (weakOperation.isCancelled) { dispatch_main_sync_safe(^{ - completedBlock(nil, nil, SDImageCacheTypeNone, finished); + completedBlock(nil, nil, SDImageCacheTypeNone, finished, url); }); } else if (error) { dispatch_main_sync_safe(^{ - completedBlock(nil, error, SDImageCacheTypeNone, finished); + completedBlock(nil, error, SDImageCacheTypeNone, finished, url); }); if (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut) { @@ -174,7 +177,7 @@ } dispatch_main_sync_safe(^{ - completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished); + completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url); }); }); } @@ -184,7 +187,7 @@ } dispatch_main_sync_safe(^{ - completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished); + completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url); }); } } @@ -205,7 +208,7 @@ } else if (image) { dispatch_main_sync_safe(^{ - completedBlock(image, nil, cacheType, YES); + completedBlock(image, nil, cacheType, YES, url); }); @synchronized (self.runningOperations) { [self.runningOperations removeObject:operation]; @@ -214,7 +217,7 @@ else { // Image not in cache and download disallowed by delegate dispatch_main_sync_safe(^{ - completedBlock(nil, nil, SDImageCacheTypeNone, YES); + completedBlock(nil, nil, SDImageCacheTypeNone, YES, url); }); @synchronized (self.runningOperations) { [self.runningOperations removeObject:operation]; @@ -245,6 +248,7 @@ @end + @implementation SDWebImageCombinedOperation - (void)setCancelBlock:(void (^)())cancelBlock { @@ -269,3 +273,21 @@ } @end + + +@implementation SDWebImageManager (Deprecated) + +// deprecated method, uses the non deprecated method +// adapter for the completion block +- (id )downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock { + return [self downloadImageWithURL:url + options:options + progress:progressBlock + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType, finished); + } + }]; +} + +@end diff --git a/SDWebImage/SDWebImagePrefetcher.m b/SDWebImage/SDWebImagePrefetcher.m index 8c4bc2f9..8f959f6f 100644 --- a/SDWebImage/SDWebImagePrefetcher.m +++ b/SDWebImage/SDWebImagePrefetcher.m @@ -56,7 +56,7 @@ - (void)startPrefetchingAtIndex:(NSUInteger)index { if (index >= self.prefetchURLs.count) return; self.requestedCount++; - [self.manager downloadWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!finished) return; self.finishedCount++; diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 909c8721..e78003cd 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -66,7 +66,7 @@ static char operationKey; self.imageURLStorage[@(state)] = url; __weak UIButton *wself = self; - id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + 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(^{ __strong UIButton *sself = wself; @@ -109,7 +109,7 @@ static char operationKey; if (url) { __weak UIButton *wself = self; - id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + 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(^{ __strong UIButton *sself = wself; diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 1eb817a1..1816f7b5 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -34,24 +34,20 @@ static char operationKey; if (url) { __weak UIImageView *wself = self; - id operation = [SDWebImageManager.sharedManager downloadWithURL:url - options:options - progress:progressBlock - completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) - { - if (!wself) return; - dispatch_main_sync_safe (^ - { - if (!wself) return; - if (image) { - wself.highlightedImage = image; - [wself setNeedsLayout]; - } - if (completedBlock && finished) { - completedBlock(image, error, cacheType); - } - }); - }]; + 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 (^ + { + if (!wself) return; + if (image) { + wself.highlightedImage = image; + [wself setNeedsLayout]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType); + } + }); + }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } } diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 201e9554..0c47c0f8 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -50,7 +50,7 @@ static char operationArrayKey; if (url) { __weak UIImageView *wself = self; - id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + 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(^{ if (!wself) return; @@ -85,7 +85,7 @@ static char operationArrayKey; NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; for (NSURL *logoImageURL in arrayOfURLs) { - id operation = [SDWebImageManager.sharedManager downloadWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (!wself) return; dispatch_main_sync_safe(^{ __strong UIImageView *sself = wself; From 654a9c98ea027a9f477598f943fbe37e3c31b4f6 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 11:32:28 +0300 Subject: [PATCH 10/23] Pass image URL in completion blocks - step 2: - created block type `SDWebImageCompletionBlock` that contains NSURL* param - deprecated all MKAnnotationView(WebCache) `setImage*` methods. Replaced with `loadImage*` methods that use the `SDWebImageCompletionBlock` as completion block type - created WebCacheDeprecated category on MKAnnotationView (to avoid collisions, we didn't name it Deprecated) - replaced the usages of the deprecated items with the new ones --- SDWebImage/MKAnnotationView+WebCache.h | 29 ++++++++--- SDWebImage/MKAnnotationView+WebCache.m | 68 ++++++++++++++++++++------ SDWebImage/SDWebImageManager.h | 3 +- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index 2be81c5b..724f1a86 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -18,7 +18,7 @@ * Get the current image URL. * * Note that because of the limitations of categories this property can get out of sync - * if you use setImage: directly. + * if you use loadImage: directly. */ - (NSURL *)imageURL; @@ -29,7 +29,7 @@ * * @param url The url for the image. */ -- (void)setImageWithURL:(NSURL *)url; +- (void)loadImageWithURL:(NSURL *)url; /** * Set the imageView `image` with an `url` and a placeholder. @@ -38,9 +38,9 @@ * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @see setImageWithURL:placeholderImage:options: + * @see loadImageWithURL:placeholderImage:options: */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -51,7 +51,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. @@ -64,7 +64,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. @@ -78,7 +78,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -93,7 +93,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Cancel the current download @@ -101,3 +101,16 @@ - (void)cancelCurrentImageLoad; @end + + +@interface MKAnnotationView (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadImageWithURL:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:`"); + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:completed:`"); + +@end diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index 2a29235d..88166566 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -14,33 +14,32 @@ static char operationKey; @implementation MKAnnotationView (WebCache) -- (NSURL *)imageURL; -{ +- (NSURL *)imageURL { return objc_getAssociatedObject(self, &imageURLKey); } -- (void)setImageWithURL:(NSURL *)url +- (void)loadImageWithURL:(NSURL *)url { - [self setImageWithURL:url placeholderImage:nil options:0 completed:nil]; + [self loadImageWithURL:url placeholderImage:nil options:0 completed:nil]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url placeholderImage:placeholder options:options completed:nil]; } -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -57,7 +56,7 @@ static char operationKey; sself.image = image; } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; @@ -75,3 +74,44 @@ static char operationKey; } @end + + +@implementation MKAnnotationView (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url { + [self loadImageWithURL:url placeholderImage:nil options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +@end diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 3aa97836..e40ceeca 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -77,7 +77,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { SDWebImageDelayPlaceholder = 1 << 9 }; -typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); +typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); @@ -229,6 +229,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; #pragma mark - Deprecated +typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); From 7108b4f404331566ed2056ab4baa30961d3be201 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 11:49:27 +0300 Subject: [PATCH 11/23] Pass image URL in completion blocks - step 3: - deprecated all UIButton(WebCache) `setImage*` methods. Replaced with `loadImage*` methods that use the `SDWebImageCompletionBlock` as completion block type - created WebCacheDeprecated category on UIButton (to avoid collisions, we didn't name it Deprecated) - replaced the usages of the deprecated items with the new ones --- SDWebImage/UIButton+WebCache.h | 49 ++++++++---- SDWebImage/UIButton+WebCache.m | 132 +++++++++++++++++++++++++-------- 2 files changed, 138 insertions(+), 43 deletions(-) diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index 16205718..d966044a 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -34,7 +34,7 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state; /** * Set the imageView `image` with an `url` and a placeholder. @@ -44,9 +44,9 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @see setImageWithURL:placeholderImage:options: + * @see loadImageWithURL:placeholderImage:options: */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -58,7 +58,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. @@ -72,7 +72,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. @@ -87,7 +87,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -103,7 +103,7 @@ * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. */ -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`. @@ -113,7 +113,7 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; /** * Set the backgroundImageView `image` with an `url` and a placeholder. @@ -123,9 +123,9 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @see setImageWithURL:placeholderImage:options: + * @see loadImageWithURL:placeholderImage:options: */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. @@ -137,7 +137,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the backgroundImageView `image` with an `url`. @@ -151,7 +151,7 @@ * `UIImage` object, the `NSError` object describing error that occurred, and an * `SDImageCacheType` enum describing the source of the image obtained from. */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`, placeholder. @@ -166,7 +166,7 @@ * `UIImage` object, the `NSError` object describing error that occurred, and an * `SDImageCacheType` enum describing the source of the image obtained from. */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. @@ -181,7 +181,7 @@ * `UIImage` object, the `NSError` object describing error that occurred, and an * `SDImageCacheType` enum describing the source of the image obtained from. */ -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Cancel the current download @@ -189,3 +189,24 @@ - (void)cancelCurrentImageLoad; @end + + +@interface UIButton (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:options:`"); + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:options:completed:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:options:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); + +@end diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index e78003cd..70bf2d04 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -14,8 +14,7 @@ static char operationKey; @implementation UIButton (WebCache) -- (NSURL *)currentImageURL; -{ +- (NSURL *)currentImageURL { NSURL *url = self.imageURLStorage[@(self.state)]; if (!url) @@ -26,33 +25,31 @@ static char operationKey; return url; } -- (NSURL *)imageURLForState:(UIControlState)state; -{ +- (NSURL *)imageURLForState:(UIControlState)state { return self.imageURLStorage[@(state)]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state -{ - [self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self setImage:placeholder forState:state]; [self cancelCurrentImageLoad]; @@ -75,34 +72,34 @@ static char operationKey; [sself setImage:image forState:state]; } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { - [self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { - [self setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; [self setBackgroundImage:placeholder forState:state]; @@ -118,7 +115,7 @@ static char operationKey; [sself setBackgroundImage:image forState:state]; } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; @@ -149,3 +146,80 @@ static char operationKey; } @end + + +@implementation UIButton (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +@end From 939f68d27e4966f92bec6bffac33ce9d5d7eb832 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 11:55:02 +0300 Subject: [PATCH 12/23] Updated MKAnnotation view category documentation (forth param for the completion block) + alignaments --- SDWebImage/MKAnnotationView+WebCache.h | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index 724f1a86..36369df6 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -36,7 +36,7 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. * @see loadImageWithURL:placeholderImage:options: */ @@ -47,10 +47,11 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ + - (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** @@ -58,11 +59,12 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; @@ -71,12 +73,13 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; @@ -85,13 +88,14 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; From 673fca91131fd525c8c73c12f109d566bd5749e3 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:00:23 +0300 Subject: [PATCH 13/23] Documentation alignaments --- SDWebImage/SDImageCache.h | 26 +++++++++++++------------- SDWebImage/SDWebImageDownloader.h | 20 ++++++++++---------- SDWebImage/SDWebImageManager.h | 14 +++++++------- SDWebImage/SDWebImagePrefetcher.h | 16 +++++++++------- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index df4eebdc..97cc7485 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -73,15 +73,15 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca * Store an image into memory and disk cache at the given key. * * @param image The image to store - * @param key The unique image cache key, usually it's image absolute URL + * @param key The unique image cache key, usually it's image absolute URL */ - (void)storeImage:(UIImage *)image forKey:(NSString *)key; /** * Store an image into memory and optionally disk cache at the given key. * - * @param image The image to store - * @param key The unique image cache key, usually it's image absolute URL + * @param image The image to store + * @param key The unique image cache key, usually it's image absolute URL * @param toDisk Store the image to disk cache if YES */ - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; @@ -89,13 +89,13 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca /** * Store an image into memory and optionally disk cache at the given key. * - * @param image The image to store + * @param image The image to store * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage - * @param imageData The image data as returned by the server, this representation will be used for disk storage - * instead of converting the given image object into a storable/compressed image format in order - * to save quality and CPU - * @param key The unique image cache key, usually it's image absolute URL - * @param toDisk Store the image to disk cache if YES + * @param imageData The image data as returned by the server, this representation will be used for disk storage + * instead of converting the given image object into a storable/compressed image format in order + * to save quality and CPU + * @param key The unique image cache key, usually it's image absolute URL + * @param toDisk Store the image to disk cache if YES */ - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; @@ -131,7 +131,7 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca /** * Remove the image from memory and disk cache synchronously * - * @param key The unique image cache key + * @param key The unique image cache key * @param completionBlock An block that should be executed after the image has been removed (optional) */ - (void)removeImageForKey:(NSString *)key withCompletition:(void (^)())completion; @@ -139,7 +139,7 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca /** * Remove the image from memory and optionally disk cache synchronously * - * @param key The unique image cache key + * @param key The unique image cache key * @param fromDisk Also remove cache entry from disk if YES */ - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; @@ -147,8 +147,8 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca /** * Remove the image from memory and optionally disk cache synchronously * - * @param key The unique image cache key - * @param fromDisk Also remove cache entry from disk if YES + * @param key The unique image cache key + * @param fromDisk Also remove cache entry from disk if YES * @param completionBlock An block that should be executed after the image has been removed (optional) */ - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletition:(void (^)())completion; diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index ffe5aa9d..edbe7104 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -129,17 +129,17 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, * * @see SDWebImageDownloaderDelegate * - * @param url The URL to the image to download - * @param options The options to be used for this download - * @param progressBlock A block called repeatedly while the image is downloading + * @param url The URL to the image to download + * @param options The options to be used for this download + * @param progressBlock A block called repeatedly while the image is downloading * @param completedBlock A block called once the download is completed. - * If the download succeeded, the image parameter is set, in case of error, - * error parameter is set with the error. The last parameter is always YES - * if SDWebImageDownloaderProgressiveDownload isn't use. With the - * SDWebImageDownloaderProgressiveDownload option, this block is called - * repeatedly with the partial image object and the finished argument set to NO - * before to be called a last time with the full image and finished argument - * set to YES. In case of error, the finished argument is always YES. + * If the download succeeded, the image parameter is set, in case of error, + * error parameter is set with the error. The last parameter is always YES + * if SDWebImageDownloaderProgressiveDownload isn't use. With the + * SDWebImageDownloaderProgressiveDownload option, this block is called + * repeatedly with the partial image object and the finished argument set to NO + * before to be called a last time with the full image and finished argument + * set to YES. In case of error, the finished argument is always YES. * * @return A cancellable SDWebImageOperation */ diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index e40ceeca..11ae5e8c 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -92,7 +92,7 @@ typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *er * Controls which image should be downloaded when the image is not found in the cache. * * @param imageManager The current `SDWebImageManager` - * @param imageURL The url of the image to be downloaded + * @param imageURL The url of the image to be downloaded * * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. */ @@ -103,8 +103,8 @@ typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *er * NOTE: This method is called from a global queue in order to not to block the main thread. * * @param imageManager The current `SDWebImageManager` - * @param image The image to transform - * @param imageURL The url of the image to transform + * @param image The image to transform + * @param imageURL The url of the image to transform * * @return The transformed image object. */ @@ -169,9 +169,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; /** * Downloads the image at the given URL if not present in cache or return the cached version otherwise. * - * @param url The URL to the image - * @param options A mask to specify options to use for this request - * @param progressBlock A block called while image is downloading + * @param url The URL to the image + * @param options A mask to specify options to use for this request + * @param progressBlock A block called while image is downloading * @param completedBlock A block called when operation has been completed. * * This parameter is required. @@ -197,7 +197,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; * Saves image to cache for given URL * * @param image The image to cache - * @param url The URL to the image + * @param url The URL to the image * */ diff --git a/SDWebImage/SDWebImagePrefetcher.h b/SDWebImage/SDWebImagePrefetcher.h index 5664ac5c..3829033a 100644 --- a/SDWebImage/SDWebImagePrefetcher.h +++ b/SDWebImage/SDWebImagePrefetcher.h @@ -19,17 +19,17 @@ * Called when an image was prefetched. * * @param imagePrefetcher The current image prefetcher - * @param imageURL The image url that was prefetched - * @param finishedCount The total number of images that were prefetched (successful or not) - * @param totalCount The total number of images that were to be prefetched + * @param imageURL The image url that was prefetched + * @param finishedCount The total number of images that were prefetched (successful or not) + * @param totalCount The total number of images that were to be prefetched */ - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; /** * Called when all images are prefetched. * @param imagePrefetcher The current image prefetcher - * @param totalCount The total number of images that were prefetched (whether successful or not) - * @param skippedCount The total number of images that were skipped + * @param totalCount The total number of images that were prefetched (whether successful or not) + * @param skippedCount The total number of images that were skipped */ - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; @@ -77,8 +77,10 @@ * currently one image is downloaded at a time, * and skips images for failed downloads and proceed to the next image in the list * - * @param urls list of URLs to prefetch - * @param progressBlock block to be called when progress updates; first parameter is the number of completed (successful or not) requests, second parameter is the total number of images originally requested to be prefetched + * @param urls list of URLs to prefetch + * @param progressBlock block to be called when progress updates; + * first parameter is the number of completed (successful or not) requests, + * second parameter is the total number of images originally requested to be prefetched * @param completionBlock block to be called when prefetching is completed */ - (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock; From c38409b813f9199b7065d38353c5570e96ad182c Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:04:07 +0300 Subject: [PATCH 14/23] Updated UIButton category documentation (forth param for the completion block) + alignaments --- SDWebImage/UIButton+WebCache.h | 94 ++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index d966044a..4ddc5d6b 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -31,7 +31,7 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ - (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state; @@ -41,8 +41,8 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. * @see loadImageWithURL:placeholderImage:options: */ @@ -53,10 +53,10 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ - (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; @@ -65,12 +65,13 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; @@ -79,13 +80,14 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. - * @param placeholder The image to be set initially, until the image request finishes. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; @@ -94,14 +96,15 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; @@ -110,7 +113,7 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ - (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; @@ -120,8 +123,8 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. * @see loadImageWithURL:placeholderImage:options: */ @@ -132,10 +135,10 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ - (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; @@ -144,12 +147,13 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. - * @param completedBlock A block object to be executed after the request operation - * completed. This block has no return value and takes three argument: the requested - * `UIImage` object, the `NSError` object describing error that occurred, and an - * `SDImageCacheType` enum describing the source of the image obtained from. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; @@ -158,13 +162,14 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param state The state that uses the specified title. The values are described in UIControlState. - * @param placeholder The image to be set initially, until the image request finishes. - * @param completedBlock A block object to be executed after the request operation - * completed. This block has no return value and takes three argument: the requested - * `UIImage` object, the `NSError` object describing error that occurred, and an - * `SDImageCacheType` enum describing the source of the image obtained from. + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; @@ -173,13 +178,14 @@ * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block object to be executed after the request operation - * completed. This block has no return value and takes three argument: the requested - * `UIImage` object, the `NSError` object describing error that occurred, and an - * `SDImageCacheType` enum describing the source of the image obtained from. + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ - (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; From 76b552e21e5f7c7bceee46ab336cb9c6ee57f3c7 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:12:58 +0300 Subject: [PATCH 15/23] Pass image URL in completion blocks - step 4: - deprecated all UIImageView(HighlightedWebCache) `setImage*` methods. Replaced with `loadImage*` methods that use the `SDWebImageCompletionBlock` as completion block type - created HighlightedWebCacheDeprecated category on UIImageView (to avoid collisions, we didn't name it Deprecated) - replaced the usages of the deprecated items with the new ones --- SDWebImage/UIImageView+HighlightedWebCache.h | 46 ++++++++++------ SDWebImage/UIImageView+HighlightedWebCache.m | 57 ++++++++++++++++---- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index 40646ea4..cbc97a50 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -21,59 +21,73 @@ * * @param url The url for the image. */ -- (void)setHighlightedImageWithURL:(NSURL *)url; +- (void)loadHighlightedImageWithURL:(NSURL *)url; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; /** * Set the imageView `highlightedImage` with an `url`. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. * * The downloand is asynchronous and cached. * - * @param url The url for the image. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param progressBlock A block called while image is downloading - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock; - +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +@end + + +@interface UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:`"); + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:progress:completed:`"); @end diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 1816f7b5..5a5776bd 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -13,23 +13,23 @@ static char operationKey; @implementation UIImageView (HighlightedWebCache) -- (void)setHighlightedImageWithURL:(NSURL *)url { - [self setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +- (void)loadHighlightedImageWithURL:(NSURL *)url { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { - [self setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; } -- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; +- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; } -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; if (url) { @@ -44,7 +44,7 @@ static char operationKey; [wself setNeedsLayout]; } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; @@ -53,3 +53,40 @@ static char operationKey; } @end + + +@implementation UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self loadHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +@end From 21b230f28f07206dfe8e40b1e0e817c9d09813dc Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:13:39 +0300 Subject: [PATCH 16/23] Fixed misspell (downloand -> download) --- SDWebImage/MKAnnotationView+WebCache.h | 12 +++++----- SDWebImage/UIButton+WebCache.h | 24 ++++++++++---------- SDWebImage/UIImageView+HighlightedWebCache.h | 10 ++++---- SDWebImage/UIImageView+WebCache.h | 12 +++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index 36369df6..b63c180c 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -25,7 +25,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. */ @@ -34,7 +34,7 @@ /** * Set the imageView `image` with an `url` and a placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -45,7 +45,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -57,7 +57,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param completedBlock A block called when operation has been completed. This block has no return value @@ -71,7 +71,7 @@ /** * Set the imageView `image` with an `url`, placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -86,7 +86,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index 4ddc5d6b..dc4acfb7 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -29,7 +29,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -39,7 +39,7 @@ /** * Set the imageView `image` with an `url` and a placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -51,7 +51,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -63,7 +63,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -78,7 +78,7 @@ /** * Set the imageView `image` with an `url`, placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -94,7 +94,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -111,7 +111,7 @@ /** * Set the backgroundImageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -121,7 +121,7 @@ /** * Set the backgroundImageView `image` with an `url` and a placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -133,7 +133,7 @@ /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -145,7 +145,7 @@ /** * Set the backgroundImageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -160,7 +160,7 @@ /** * Set the backgroundImageView `image` with an `url`, placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. @@ -176,7 +176,7 @@ /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index cbc97a50..37375901 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -17,7 +17,7 @@ /** * Set the imageView `highlightedImage` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. */ @@ -26,7 +26,7 @@ /** * Set the imageView `highlightedImage` with an `url` and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. @@ -36,7 +36,7 @@ /** * Set the imageView `highlightedImage` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param completedBlock A block called when operation has been completed. This block has no return value @@ -50,7 +50,7 @@ /** * Set the imageView `highlightedImage` with an `url` and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. @@ -65,7 +65,7 @@ /** * Set the imageView `highlightedImage` with an `url` and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index 40e2f2cc..5c75e33c 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -55,7 +55,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. */ @@ -64,7 +64,7 @@ /** * Set the imageView `image` with an `url` and a placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -75,7 +75,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -86,7 +86,7 @@ /** * Set the imageView `image` with an `url`. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param completedBlock A block called when operation has been completed. This block as no return value @@ -99,7 +99,7 @@ /** * Set the imageView `image` with an `url`, placeholder. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. @@ -113,7 +113,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. From 81b5e72a9cf872c71e8d9c516bd956bda33c5713 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:26:12 +0300 Subject: [PATCH 17/23] Pass image URL in completion blocks - step 5: - deprecated all UIImageView(WebCache) `setImage*` methods. Replaced with `loadImage*` methods that use the `SDWebImageCompletionBlock` as completion block type - created WebCacheDeprecated category on UIImageView (to avoid collisions, we didn't name it Deprecated) - replaced the usages of the deprecated items with the new ones --- SDWebImage/UIImageView+WebCache.h | 76 ++++++++++++++++++----------- SDWebImage/UIImageView+WebCache.m | 80 +++++++++++++++++++++++++------ 2 files changed, 113 insertions(+), 43 deletions(-) diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index 5c75e33c..731607a7 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -31,10 +31,10 @@ autorelease]; } - // Here we use the provided setImageWithURL: method to load the web image + // Here we use the provided loadImageWithURL: method to load the web image // Ensure you use a placeholder image otherwise cells will be initialized with no image - [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] - placeholderImage:[UIImage imageNamed:@"placeholder"]]; + [cell.imageView loadImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder"]]; cell.textLabel.text = @"My Text"; return cell; @@ -48,7 +48,7 @@ * Get the current image URL. * * Note that because of the limitations of categories this property can get out of sync - * if you use setImage: directly. + * if you use loadImage: directly. */ - (NSURL *)imageURL; @@ -59,87 +59,91 @@ * * @param url The url for the image. */ -- (void)setImageWithURL:(NSURL *)url; +- (void)loadImageWithURL:(NSURL *)url; /** * Set the imageView `image` with an `url` and a placeholder. * * The download is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @see setImageWithURL:placeholderImage:options: + * @see loadImageWithURL:placeholderImage:options: */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. * * The download is asynchronous and cached. * - * @param url The url for the image. + * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. * * The download is asynchronous and cached. * - * @param url The url for the image. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. * * The download is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. * * The download is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. * * The download is asynchronous and cached. * - * @param url The url for the image. - * @param placeholder The image to be set initially, until the image request finishes. - * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. - * @param progressBlock A block called while image is downloading - * @param completedBlock A block called when operation has been completed. This block as no return value + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value * and takes the requested UIImage as first parameter. In case of error the image parameter * is nil and the second parameter may contain an NSError. The third parameter is a Boolean * indicating if the image was retrived from the local cache of from the network. + * The forth parameter is the original image url. */ -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; /** * Download an array of images and starts them in an animation loop @@ -156,3 +160,17 @@ - (void)cancelCurrentArrayLoad; @end + + +@interface UIImageView (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadImageWithURL:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options`"); + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:progress:completed:`"); + +@end diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 0c47c0f8..85bde1eb 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -15,31 +15,31 @@ static char operationArrayKey; @implementation UIImageView (WebCache) -- (void)setImageWithURL:(NSURL *)url { - [self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +- (void)loadImageWithURL:(NSURL *)url { + [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; } -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; } -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { +- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.image = placeholder; @@ -64,7 +64,7 @@ static char operationArrayKey; } } if (completedBlock && finished) { - completedBlock(image, error, cacheType); + completedBlock(image, error, cacheType, url); } }); }]; @@ -130,3 +130,55 @@ static char operationArrayKey; } @end + + +@implementation UIImageView (WebCacheDeprecated) + +- (void)setImageWithURL:(NSURL *)url { + [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; + +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; + +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self loadImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; + +} + +@end From 03a751430de30829964846742a17cb6e2d0c1963 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 12:27:08 +0300 Subject: [PATCH 18/23] Pass image URL in completion blocks - step 6: - deprecated block type `SDWebImageCompletedBlock `, replaced with `SDWebImageCompletedBlock ` that contains NSURL* param --- SDWebImage/SDWebImageManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 11ae5e8c..664b3089 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -229,7 +229,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; #pragma mark - Deprecated -typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); +typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`"); typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); From ea663b96028ba9e2ebd47a359962d62b7585cc21 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 21:54:25 +0300 Subject: [PATCH 19/23] As discussed with @rs, prefixed all the new methods to sd_set* --- SDWebImage/MKAnnotationView+WebCache.h | 28 ++++---- SDWebImage/MKAnnotationView+WebCache.m | 35 +++++----- SDWebImage/UIButton+WebCache.h | 52 +++++++-------- SDWebImage/UIButton+WebCache.m | 68 ++++++++++---------- SDWebImage/UIImageView+HighlightedWebCache.h | 20 +++--- SDWebImage/UIImageView+HighlightedWebCache.m | 28 ++++---- SDWebImage/UIImageView+WebCache.h | 38 +++++------ SDWebImage/UIImageView+WebCache.m | 40 ++++++------ 8 files changed, 154 insertions(+), 155 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index b63c180c..2f9a8f77 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -18,7 +18,7 @@ * Get the current image URL. * * Note that because of the limitations of categories this property can get out of sync - * if you use loadImage: directly. + * if you use sd_setImage: directly. */ - (NSURL *)imageURL; @@ -29,7 +29,7 @@ * * @param url The url for the image. */ -- (void)loadImageWithURL:(NSURL *)url; +- (void)sd_setImageWithURL:(NSURL *)url; /** * Set the imageView `image` with an `url` and a placeholder. @@ -38,9 +38,9 @@ * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @see loadImageWithURL:placeholderImage:options: + * @see sd_setImageWithURL:placeholderImage:options: */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -52,7 +52,7 @@ * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. @@ -66,7 +66,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. @@ -81,7 +81,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -97,7 +97,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Cancel the current download @@ -109,12 +109,12 @@ @interface MKAnnotationView (WebCacheDeprecated) -- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadImageWithURL:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:`"); +- (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:`"); -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:completed:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:completed:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:completed:`"); +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); +- (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:`"); @end diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index 88166566..3eca7464 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -18,28 +18,27 @@ static char operationKey; return objc_getAssociatedObject(self, &imageURLKey); } -- (void)loadImageWithURL:(NSURL *)url -{ - [self loadImageWithURL:url placeholderImage:nil options:0 completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url placeholderImage:placeholder options:options completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -79,19 +78,19 @@ static char operationKey; @implementation MKAnnotationView (WebCacheDeprecated) - (void)setImageWithURL:(NSURL *)url { - [self loadImageWithURL:url placeholderImage:nil options:0 completed:nil]; + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url placeholderImage:placeholder options:options completed:nil]; + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; } - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -99,7 +98,7 @@ static char operationKey; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -107,7 +106,7 @@ static char operationKey; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index dc4acfb7..38e4ece1 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -34,7 +34,7 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state; /** * Set the imageView `image` with an `url` and a placeholder. @@ -44,9 +44,9 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @see loadImageWithURL:placeholderImage:options: + * @see sd_setImageWithURL:placeholderImage:options: */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -58,7 +58,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. @@ -73,7 +73,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. @@ -89,7 +89,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -106,7 +106,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`. @@ -116,7 +116,7 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; /** * Set the backgroundImageView `image` with an `url` and a placeholder. @@ -126,9 +126,9 @@ * @param url The url for the image. * @param state The state that uses the specified title. The values are described in UIControlState. * @param placeholder The image to be set initially, until the image request finishes. - * @see loadImageWithURL:placeholderImage:options: + * @see sd_setImageWithURL:placeholderImage:options: */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. @@ -140,7 +140,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the backgroundImageView `image` with an `url`. @@ -155,7 +155,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`, placeholder. @@ -171,7 +171,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the backgroundImageView `image` with an `url`, placeholder and custom options. @@ -187,7 +187,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Cancel the current download @@ -199,20 +199,20 @@ @interface UIButton (WebCacheDeprecated) -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:`"); -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:`"); -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:options:`"); +- (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:`"); -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:completed:`"); -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:completed:`"); -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:forState:placeholderImage:options:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:options:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:completed:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:completed:`"); -- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`"); +- (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:`"); @end diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 70bf2d04..bd9cec7e 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -29,27 +29,27 @@ static char operationKey; return self.imageURLStorage[@(state)]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state { - [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self setImage:placeholder forState:state]; [self cancelCurrentImageLoad]; @@ -79,27 +79,27 @@ static char operationKey; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; } -- (void)loadBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; [self setBackgroundImage:placeholder forState:state]; @@ -151,19 +151,19 @@ static char operationKey; @implementation UIButton (WebCacheDeprecated) - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { - [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -171,7 +171,7 @@ static char operationKey; } - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -179,7 +179,7 @@ static char operationKey; } - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -187,19 +187,19 @@ static char operationKey; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -207,7 +207,7 @@ static char operationKey; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -215,7 +215,7 @@ static char operationKey; } - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self loadBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } diff --git a/SDWebImage/UIImageView+HighlightedWebCache.h b/SDWebImage/UIImageView+HighlightedWebCache.h index 37375901..68b64498 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.h +++ b/SDWebImage/UIImageView+HighlightedWebCache.h @@ -21,7 +21,7 @@ * * @param url The url for the image. */ -- (void)loadHighlightedImageWithURL:(NSURL *)url; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url; /** * Set the imageView `highlightedImage` with an `url` and custom options. @@ -31,7 +31,7 @@ * @param url The url for the image. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; /** * Set the imageView `highlightedImage` with an `url`. @@ -45,7 +45,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. @@ -60,7 +60,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `highlightedImage` with an `url` and custom options. @@ -76,18 +76,18 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; @end @interface UIImageView (HighlightedWebCacheDeprecated) -- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:`"); -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:`"); +- (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 `loadHighlightedImageWithURL:completed:`"); -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:completed:`"); -- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadHighlightedImageWithURL:options:progress:completed:`"); +- (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:`"); @end diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 5a5776bd..11cd32e3 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -13,23 +13,23 @@ static char operationKey; @implementation UIImageView (HighlightedWebCache) -- (void)loadHighlightedImageWithURL:(NSURL *)url { - [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; } -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { - [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; } -- (void)loadHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { - [self loadHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; } -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { - [self loadHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; } -- (void)loadHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; if (url) { @@ -58,15 +58,15 @@ static char operationKey; @implementation UIImageView (HighlightedWebCacheDeprecated) - (void)setHighlightedImageWithURL:(NSURL *)url { - [self loadHighlightedImageWithURL:url options:0 progress:nil completed:nil]; + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; } - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { - [self loadHighlightedImageWithURL:url options:options progress:nil completed:nil]; + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; } - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self loadHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -74,7 +74,7 @@ static char operationKey; } - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self loadHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -82,7 +82,7 @@ static char operationKey; } - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { - [self loadHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index 731607a7..e1a733c3 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -31,10 +31,10 @@ autorelease]; } - // Here we use the provided loadImageWithURL: method to load the web image + // Here we use the provided sd_setImageWithURL: method to load the web image // Ensure you use a placeholder image otherwise cells will be initialized with no image - [cell.imageView loadImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] - placeholderImage:[UIImage imageNamed:@"placeholder"]]; + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder"]]; cell.textLabel.text = @"My Text"; return cell; @@ -48,7 +48,7 @@ * Get the current image URL. * * Note that because of the limitations of categories this property can get out of sync - * if you use loadImage: directly. + * if you use sd_setImage: directly. */ - (NSURL *)imageURL; @@ -59,7 +59,7 @@ * * @param url The url for the image. */ -- (void)loadImageWithURL:(NSURL *)url; +- (void)sd_setImageWithURL:(NSURL *)url; /** * Set the imageView `image` with an `url` and a placeholder. @@ -68,9 +68,9 @@ * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. - * @see loadImageWithURL:placeholderImage:options: + * @see sd_setImageWithURL:placeholderImage:options: */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -81,7 +81,7 @@ * @param placeholder The image to be set initially, until the image request finishes. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; /** * Set the imageView `image` with an `url`. @@ -95,7 +95,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder. @@ -110,7 +110,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -126,7 +126,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; /** * Set the imageView `image` with an `url`, placeholder and custom options. @@ -143,7 +143,7 @@ * indicating if the image was retrived from the local cache of from the network. * The forth parameter is the original image url. */ -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; /** * Download an array of images and starts them in an animation loop @@ -164,13 +164,13 @@ @interface UIImageView (WebCacheDeprecated) -- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `loadImageWithURL:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options`"); +- (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`"); -- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:completed:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:completed:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:completed:`"); -- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `loadImageWithURL:placeholderImage:options:progress:completed:`"); +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); +- (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)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:`"); @end diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 85bde1eb..d279228c 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -15,31 +15,31 @@ static char operationArrayKey; @implementation UIImageView (WebCache) -- (void)loadImageWithURL:(NSURL *)url { - [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; } -- (void)loadImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; } -- (void)loadImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { [self cancelCurrentImageLoad]; objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.image = placeholder; @@ -135,19 +135,19 @@ static char operationArrayKey; @implementation UIImageView (WebCacheDeprecated) - (void)setImageWithURL:(NSURL *)url { - [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { - [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { - [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; } - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -155,7 +155,7 @@ static char operationArrayKey; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -164,7 +164,7 @@ static char operationArrayKey; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } @@ -173,7 +173,7 @@ static char operationArrayKey; } - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { - [self loadImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, cacheType); } From e116aa5ce03b9aee2033cec9264e5eb8702af8f8 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 21:58:20 +0300 Subject: [PATCH 20/23] Updated some older code to match the coding style --- SDWebImage/UIButton+WebCache.m | 3 +-- SDWebImage/UIImageView+WebCache.m | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index bd9cec7e..27857cf6 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -133,8 +133,7 @@ static char operationKey; } } -- (NSMutableDictionary *)imageURLStorage; -{ +- (NSMutableDictionary *)imageURLStorage { NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); if (!storage) { diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index d279228c..668162f7 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -72,13 +72,11 @@ static char operationArrayKey; } } -- (NSURL *)imageURL; -{ +- (NSURL *)imageURL { return objc_getAssociatedObject(self, &imageURLKey); } -- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs -{ +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { [self cancelCurrentArrayLoad]; __weak UIImageView *wself = self; From 136daba9df8ad46fb5bccb5dd8954e2fd2dc0fbe Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 22:19:22 +0300 Subject: [PATCH 21/23] Added proper handling for SDWebImageDownloaderLowPriority (aka NSOperationQueuePriorityLow). Fixes #713 #745 --- SDWebImage/SDWebImageDownloader.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 251bc513..a67eb9dc 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -155,6 +155,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; if (options & SDWebImageDownloaderHighPriority) { operation.queuePriority = NSOperationQueuePriorityHigh; + } else if (options & SDWebImageDownloaderLowPriority) { + operation.queuePriority = NSOperationQueuePriorityLow; } [wself.downloadQueue addOperation:operation]; From eb91fdd3b82bfce586c7d439224576dcc93e0a1c Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 23:05:14 +0300 Subject: [PATCH 22/23] Fixed issue #529 - if the `cacheKeyFilter` was set, this was ignored when computing the `scaledImageForKey`. For most of the developers that did not set `cacheKeyFilter`, the code will work exactly the same --- SDWebImage/SDWebImageDownloaderOperation.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index a0b7db2f..b93be75a 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -10,6 +10,7 @@ #import "SDWebImageDecoder.h" #import "UIImage+MultiFormat.h" #import +#import "SDWebImageManager.h" @interface SDWebImageDownloaderOperation () { BOOL _executing; @@ -285,7 +286,8 @@ if (partialImageRef) { UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation]; - UIImage *scaledImage = [self scaledImageForKey:self.request.URL.absoluteString image:image]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + UIImage *scaledImage = [self scaledImageForKey:key image:image]; image = [UIImage decodedImageWithImage:scaledImage]; CGImageRelease(partialImageRef); dispatch_main_sync_safe(^{ @@ -353,7 +355,8 @@ UIImage *image = [UIImage sd_imageWithData:self.imageData]; - image = [self scaledImageForKey:self.request.URL.absoluteString image:image]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + image = [self scaledImageForKey:key image:image]; if (!image.images) // Do not force decod animated GIFs { From af3e4f87e4a26606e55ec605c19958e17edc0d65 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Thu, 19 Jun 2014 23:24:08 +0300 Subject: [PATCH 23/23] Returning error in setImage completedBlock if the url was nil. Added `dispatch_main_async_safe` macro. Fixes #505 --- SDWebImage/MKAnnotationView+WebCache.m | 7 +++++++ SDWebImage/SDWebImageCompat.h | 10 ++++++++-- SDWebImage/UIButton+WebCache.m | 17 +++++++++++++++-- SDWebImage/UIImageView+HighlightedWebCache.m | 7 +++++++ SDWebImage/UIImageView+WebCache.m | 7 +++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index 3eca7464..b1d62421 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -60,6 +60,13 @@ static char operationKey; }); }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); } } diff --git a/SDWebImage/SDWebImageCompat.h b/SDWebImage/SDWebImageCompat.h index 2d90d3ca..3d8d6360 100644 --- a/SDWebImage/SDWebImageCompat.h +++ b/SDWebImage/SDWebImageCompat.h @@ -56,7 +56,13 @@ extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); #define dispatch_main_sync_safe(block)\ if ([NSThread isMainThread]) {\ block();\ - }\ - else {\ + } else {\ dispatch_sync(dispatch_get_main_queue(), block);\ } + +#define dispatch_main_async_safe(block)\ + if ([NSThread isMainThread]) {\ + block();\ + } else {\ + dispatch_async(dispatch_get_main_queue(), block);\ + } diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 27857cf6..cb7ef948 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -17,8 +17,7 @@ static char operationKey; - (NSURL *)currentImageURL { NSURL *url = self.imageURLStorage[@(self.state)]; - if (!url) - { + if (!url) { url = self.imageURLStorage[@(UIControlStateNormal)]; } @@ -57,6 +56,13 @@ static char operationKey; if (!url) { [self.imageURLStorage removeObjectForKey:@(state)]; + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + return; } @@ -120,6 +126,13 @@ static char operationKey; }); }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); } } diff --git a/SDWebImage/UIImageView+HighlightedWebCache.m b/SDWebImage/UIImageView+HighlightedWebCache.m index 11cd32e3..07f8d089 100644 --- a/SDWebImage/UIImageView+HighlightedWebCache.m +++ b/SDWebImage/UIImageView+HighlightedWebCache.m @@ -49,6 +49,13 @@ static char operationKey; }); }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); } } diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 668162f7..25299e92 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -69,6 +69,13 @@ static char operationArrayKey; }); }]; objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); } }