Remove some unused code, fix typo, update the comments

This commit is contained in:
DreamPiggy 2017-12-17 03:05:56 +08:00
parent 37f84ce6a6
commit 91ff801611
4 changed files with 9 additions and 15 deletions

View File

@ -146,18 +146,10 @@ static inline NSString * backgroundImageURLKeyForState(UIControlState state) {
completed:completedBlock]; completed:completedBlock];
} }
- (void)sd_setImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
[self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
}
- (void)sd_cancelImageLoadForState:(UIControlState)state { - (void)sd_cancelImageLoadForState:(UIControlState)state {
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(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 { - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
} }

View File

@ -109,18 +109,18 @@
}]; }];
} }
static char animationloadOperationKey; static char animationLoadOperationKey;
// element is weak because operation instance is retained by SDWebImageManager's runningOperations property // element is weak because operation instance is retained by SDWebImageManager's runningOperations property
// we should use lock to keep thread-safe because these method may not be acessed from main queue // we should use lock to keep thread-safe because these method may not be acessed from main queue
- (NSPointerArray *)sd_animationOperationArray { - (NSPointerArray *)sd_animationOperationArray {
@synchronized(self) { @synchronized(self) {
NSPointerArray *operationsArray = objc_getAssociatedObject(self, &animationloadOperationKey); NSPointerArray *operationsArray = objc_getAssociatedObject(self, &animationLoadOperationKey);
if (operationsArray) { if (operationsArray) {
return operationsArray; return operationsArray;
} }
operationsArray = [NSPointerArray weakObjectsPointerArray]; operationsArray = [NSPointerArray weakObjectsPointerArray];
objc_setAssociatedObject(self, &animationloadOperationKey, operationsArray, OBJC_ASSOCIATION_RETAIN_NONATOMIC); objc_setAssociatedObject(self, &animationLoadOperationKey, operationsArray, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return operationsArray; return operationsArray;
} }
} }

View File

@ -12,10 +12,12 @@
#import "SDWebImageManager.h" #import "SDWebImageManager.h"
// These methods are used to support canceling for UIView image loading, it's designed to be used internal but not external.
// All the stored operations are weak, so it will be dalloced after image loading finished. If you need to store operations, use your own class to keep a strong reference for them.
@interface UIView (WebCacheOperation) @interface UIView (WebCacheOperation)
/** /**
* Set the image load operation (storage in a UIView based dictionary) * Set the image load operation (storage in a UIView based weak map table)
* *
* @param operation the operation * @param operation the operation
* @param key key for storing the operation * @param key key for storing the operation

View File

@ -16,7 +16,7 @@ static char loadOperationKey;
// key is copy, value is weak because operation instance is retained by SDWebImageManager's runningOperations property // key is copy, value is weak because operation instance is retained by SDWebImageManager's runningOperations property
// we should use lock to keep thread-safe because these method may not be acessed from main queue // we should use lock to keep thread-safe because these method may not be acessed from main queue
typedef NSMapTable<NSString *, id> SDOperationsDictionary; typedef NSMapTable<NSString *, id<SDWebImageOperation>> SDOperationsDictionary;
@implementation UIView (WebCacheOperation) @implementation UIView (WebCacheOperation)
@ -47,13 +47,13 @@ typedef NSMapTable<NSString *, id> SDOperationsDictionary;
- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key { - (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key {
// Cancel in progress downloader from queue // Cancel in progress downloader from queue
SDOperationsDictionary *operationDictionary = [self sd_operationDictionary]; SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
id operation; id<SDWebImageOperation> operation;
@synchronized (self) { @synchronized (self) {
operation = [operationDictionary objectForKey:key]; operation = [operationDictionary objectForKey:key];
} }
if (operation) { if (operation) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]){ if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]){
[(id<SDWebImageOperation>) operation cancel]; [operation cancel];
} }
@synchronized (self) { @synchronized (self) {
[operationDictionary removeObjectForKey:key]; [operationDictionary removeObjectForKey:key];