Update the comments and associated key

This commit is contained in:
DreamPiggy 2023-07-31 18:00:31 +08:00
parent 5ef6c83953
commit c614dffdfd
3 changed files with 6 additions and 7 deletions

View File

@ -21,7 +21,7 @@
/**
* Get the current image URL.
* This simply translate to `[self sd_imageURLForState:self.state]` from v5.17.0
* This simply translate to `[self sd_imageURLForState:self.state]` from v5.18.0
*/
@property (nonatomic, strong, readonly, nullable) NSURL *sd_currentImageURL;

View File

@ -32,7 +32,7 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima
*
* @note You can use method `UIView+WebCacheOperation` to investigate different queries' operation.
* @note For the history version compatible, when current UIView has property exactly called `image`, the operation key will use `NSStringFromClass(self.class)`. Include `UIImageView.image/NSImageView.image/NSButton.image` (without `UIButton`)
* @warning This property should be only used for single state view, like `UIImageView` without highlighted state. For stateful view like `UIBUtton` (one view can have multiple images loading), check their header to call correct API, like `UIButton sd_imageURLForState:`
* @warning This property should be only used for single state view, like `UIImageView` without highlighted state. For stateful view like `UIBUtton` (one view can have multiple images loading), check their header to call correct API, like `-[UIButton sd_imageOperationKeyForState:]`
*/
@property (nonatomic, strong, readonly, nullable) NSString *sd_latestOperationKey;
@ -40,7 +40,7 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima
/**
* Get the current image URL.
* This simply translate to `[self sd_imageLoadStateForKey:self.sd_latestOperationKey].url` from v5.17.0
* This simply translate to `[self sd_imageLoadStateForKey:self.sd_latestOperationKey].url` from v5.18.0
*
* @note Note that because of the limitations of categories this property can get out of sync if you use setImage: directly.
* @warning This property should be only used for single state view, like `UIImageView` without highlighted state. For stateful view like `UIBUtton` (one view can have multiple images loading), use `sd_imageLoadStateForKey:` instead. See `UIView+WebCacheState.h` for more information.
@ -92,7 +92,7 @@ typedef void(^SDSetImageBlock)(UIImage * _Nullable image, NSData * _Nullable ima
/**
* Cancel the current image load
* This simply translate to `[self sd_cancelImageLoadOperationWithKey:self.sd_latestOperationKey]` from v5.17.0
* This simply translate to `[self sd_cancelImageLoadOperationWithKey:self.sd_latestOperationKey]` from v5.18.0
*
* @warning This method should be only used for single state view, like `UIImageView` without highlighted state. For stateful view like `UIBUtton` (one view can have multiple images loading), use `sd_cancelImageLoadOperationWithKey:` instead. See `UIView+WebCacheOperation.h` for more information.
*/

View File

@ -9,7 +9,6 @@
#import "UIView+WebCacheState.h"
#import "objc/runtime.h"
static char loadStateKey;
typedef NSMutableDictionary<NSString *, SDWebImageLoadState *> SDStatesDictionary;
@implementation SDWebImageLoadState
@ -19,10 +18,10 @@ typedef NSMutableDictionary<NSString *, SDWebImageLoadState *> SDStatesDictionar
@implementation UIView (WebCacheState)
- (SDStatesDictionary *)sd_imageLoadStateDictionary {
SDStatesDictionary *states = objc_getAssociatedObject(self, &loadStateKey);
SDStatesDictionary *states = objc_getAssociatedObject(self, @selector(sd_imageLoadStateDictionary));
if (!states) {
states = [NSMutableDictionary dictionary];
objc_setAssociatedObject(self, &loadStateKey, states, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @selector(sd_imageLoadStateDictionary), states, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return states;
}