Skip to content

Commit

Permalink
Fixed SDWebImage#775, made sure all the category methods that are pub…
Browse files Browse the repository at this point in the history
…lic have the sd_ prefix (deprecated the old ones)

-there were a few exceptions where I just renamed the methods since they were added in this method
  • Loading branch information
bpoplauschi authored and devedup committed Sep 10, 2014
1 parent eb45583 commit 00d1ec9
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 84 deletions.
8 changes: 6 additions & 2 deletions SDWebImage/MKAnnotationView+WebCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Note that because of the limitations of categories this property can get out of sync
* if you use sd_setImage: directly.
*/
- (NSURL *)imageURL;
- (NSURL *)sd_imageURL;

/**
* Set the imageView `image` with an `url`.
Expand Down Expand Up @@ -102,13 +102,15 @@
/**
* Cancel the current download
*/
- (void)cancelCurrentImageLoad;
- (void)sd_cancelCurrentImageLoad;

@end


@interface MKAnnotationView (WebCacheDeprecated)

- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");

- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
Expand All @@ -117,4 +119,6 @@
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");

- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");

@end
23 changes: 13 additions & 10 deletions SDWebImage/MKAnnotationView+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#import "MKAnnotationView+WebCache.h"
#import "objc/runtime.h"
#import "UIView+WebCacheOperation.h"

static char imageURLKey;
static char operationKey;

@implementation MKAnnotationView (WebCache)

- (NSURL *)imageURL {
- (NSURL *)sd_imageURL {
return objc_getAssociatedObject(self, &imageURLKey);
}

Expand Down Expand Up @@ -59,7 +59,7 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
}
});
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"];
} else {
dispatch_main_async_safe(^{
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
Expand All @@ -70,20 +70,19 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
}
}

- (void)cancelCurrentImageLoad {
// Cancel in progress downloader from queue
id <SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
if (operation) {
[operation cancel];
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)sd_cancelCurrentImageLoad {
[self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"];
}

@end


@implementation MKAnnotationView (WebCacheDeprecated)

- (NSURL *)imageURL {
return [self sd_imageURL];
}

- (void)setImageWithURL:(NSURL *)url {
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
}
Expand Down Expand Up @@ -120,4 +119,8 @@ - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder opt
}];
}

- (void)cancelCurrentImageLoad {
[self sd_cancelCurrentImageLoad];
}

@end
9 changes: 8 additions & 1 deletion SDWebImage/NSData+ImageContentType.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*
* @return the content type as string (i.e. image/jpeg, image/gif)
*/
+ (NSString *)contentTypeForImageData:(NSData *)data;
+ (NSString *)sd_contentTypeForImageData:(NSData *)data;

@end


@interface NSData (ImageContentTypeDeprecated)

+ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");

@end
11 changes: 10 additions & 1 deletion SDWebImage/NSData+ImageContentType.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@implementation NSData (ImageContentType)

+ (NSString *)contentTypeForImageData:(NSData *)data {
+ (NSString *)sd_contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
Expand Down Expand Up @@ -38,3 +38,12 @@ + (NSString *)contentTypeForImageData:(NSData *)data {
}

@end


@implementation NSData (ImageContentTypeDeprecated)

+ (NSString *)contentTypeForImageData:(NSData *)data {
return [self sd_contentTypeForImageData:data];
}

@end
14 changes: 9 additions & 5 deletions SDWebImage/UIButton+WebCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
/**
* Get the current image URL.
*/
- (NSURL *)currentImageURL;
- (NSURL *)sd_currentImageURL;

/**
* Get the image URL for a control state.
*
* @param state Which state you want to know the URL for. The values are described in UIControlState.
*/
- (NSURL *)imageURLForState:(UIControlState)state;
- (NSURL *)sd_imageURLForState:(UIControlState)state;

/**
* Set the imageView `image` with an `url`.
Expand Down Expand Up @@ -192,18 +192,21 @@
/**
* Cancel the current image download
*/
- (void)cancelImageLoadForState:(UIControlState)state;
- (void)sd_cancelImageLoadForState:(UIControlState)state;

/**
* Cancel the current backgroundImage download
*/
- (void)cancelBackgroundImageLoadForState:(UIControlState)state;
- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;

@end


@interface UIButton (WebCacheDeprecated)

- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`");
- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`");

- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
Expand All @@ -220,6 +223,7 @@
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`");

- (void)cancelCurrentImageLoad __deprecated_msg("Use `cancelImageLoadForState:`");
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`");
- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`");

@end
48 changes: 33 additions & 15 deletions SDWebImage/UIButton+WebCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#import "UIButton+WebCache.h"
#import "objc/runtime.h"
#import "UIView+WebCacheOperation.h"

static char imageURLStorageKey;
static char operationKey;

@implementation UIButton (WebCache)

- (NSURL *)currentImageURL {
- (NSURL *)sd_currentImageURL {
NSURL *url = self.imageURLStorage[@(self.state)];

if (!url) {
Expand All @@ -24,7 +24,7 @@ - (NSURL *)currentImageURL {
return url;
}

- (NSURL *)imageURLForState:(UIControlState)state {
- (NSURL *)sd_imageURLForState:(UIControlState)state {
return self.imageURLStorage[@(state)];
}

Expand All @@ -51,7 +51,7 @@ - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placehold
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {

[self setImage:placeholder forState:state];
[self cancelCurrentImageLoad];
[self sd_cancelImageLoadForState:state];

if (!url) {
[self.imageURLStorage removeObjectForKey:@(state)];
Expand Down Expand Up @@ -82,7 +82,7 @@ - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placehold
}
});
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self sd_setImageLoadOperation:operation forState:state];
}

- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
Expand All @@ -106,7 +106,7 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state
}

- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
[self cancelCurrentImageLoad];
[self sd_cancelImageLoadForState:state];

[self setBackgroundImage:placeholder forState:state];

Expand All @@ -125,7 +125,7 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state
}
});
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self sd_setBackgroundImageLoadOperation:operation forState:state];
} else {
dispatch_main_async_safe(^{
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
Expand All @@ -136,14 +136,20 @@ - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state
}
}

- (void)sd_setImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
[self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
}

- (void)cancelCurrentImageLoad {
// Cancel in progress downloader from queue
id <SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
if (operation) {
[operation cancel];
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)sd_cancelImageLoadForState:(UIControlState)state {
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
}

- (void)sd_setBackgroundImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
[self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
}

- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
}

- (NSMutableDictionary *)imageURLStorage {
Expand All @@ -162,6 +168,14 @@ - (NSMutableDictionary *)imageURLStorage {

@implementation UIButton (WebCacheDeprecated)

- (NSURL *)currentImageURL {
return [self sd_currentImageURL];
}

- (NSURL *)imageURLForState:(UIControlState)state {
return [self sd_imageURLForState:state];
}

- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
}
Expand Down Expand Up @@ -236,7 +250,11 @@ - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state pl

- (void)cancelCurrentImageLoad {
// in a backwards compatible manner, cancel for current state
[self cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(self.state)]];
[self sd_cancelImageLoadForState:self.state];
}

- (void)cancelBackgroundImageLoadForState:(UIControlState)state {
[self sd_cancelBackgroundImageLoadForState:state];
}

@end
4 changes: 2 additions & 2 deletions SDWebImage/UIImage+GIF.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ + (UIImage *)sd_animatedGIFWithData:(NSData *)data {
for (size_t i = 0; i < count; i++) {
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);

duration += [self frameDurationAtIndex:i source:source];
duration += [self sd_frameDurationAtIndex:i source:source];

[images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];

Expand All @@ -52,7 +52,7 @@ + (UIImage *)sd_animatedGIFWithData:(NSData *)data {
return animatedImage;
}

+ (float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
+ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
float frameDuration = 0.1f;
CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
Expand Down
2 changes: 1 addition & 1 deletion SDWebImage/UIImage+MultiFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @implementation UIImage (MultiFormat)

+ (UIImage *)sd_imageWithData:(NSData *)data {
UIImage *image;
NSString *imageContentType = [NSData contentTypeForImageData:data];
NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
if ([imageContentType isEqualToString:@"image/gif"]) {
image = [UIImage sd_animatedGIFWithData:data];
}
Expand Down
11 changes: 9 additions & 2 deletions SDWebImage/UIImageView+HighlightedWebCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

#import <UIKit/UIKit.h>
#import "UIImageView+WebCache.h"
#import "SDWebImageCompat.h"
#import "SDWebImageManager.h"

/**
* Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
Expand Down Expand Up @@ -78,16 +79,22 @@
*/
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;

/**
* Cancel the current download
*/
- (void)sd_cancelCurrentHighlightedImageLoad;

@end


@interface UIImageView (HighlightedWebCacheDeprecated)

- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");

- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");

- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");

@end
Loading

0 comments on commit 00d1ec9

Please sign in to comment.