From 8c5db9484b0cb985c8fde945bd1e9ab87238ad5c Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 19 Aug 2018 12:09:31 +0800 Subject: [PATCH] Adopt all the protocol APIs which contains getter value to use property instead, to make the API easy to use or Swift user --- SDWebImage/SDAnimatedImage.h | 2 +- SDWebImage/SDDiskCache.h | 4 ++-- SDWebImage/SDDiskCache.m | 4 ++-- SDWebImage/SDImageCoder.h | 6 +++--- SDWebImage/SDImageTransformer.h | 2 +- SDWebImage/SDWebImageDownloaderOperation.h | 16 +++++++--------- SDWebImage/SDWebImageIndicator.h | 2 +- Tests/Tests/SDWebImageTestCache.m | 4 ++-- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/SDWebImage/SDAnimatedImage.h b/SDWebImage/SDAnimatedImage.h index 4a8a5270..6ae98571 100644 --- a/SDWebImage/SDAnimatedImage.h +++ b/SDWebImage/SDAnimatedImage.h @@ -43,7 +43,7 @@ /** Returns a Boolean value indicating whether all animated image frames are already pre-loaded into memory. */ -- (BOOL)isAllFramesLoaded; +@property (nonatomic, assign, readonly, getter=isAllFramesLoaded) BOOL allFramesLoaded; @end diff --git a/SDWebImage/SDDiskCache.h b/SDWebImage/SDDiskCache.h index 02e42d66..fbe893f5 100644 --- a/SDWebImage/SDDiskCache.h +++ b/SDWebImage/SDDiskCache.h @@ -85,7 +85,7 @@ @return The total data count. */ -- (NSInteger)totalCount; +- (NSUInteger)totalCount; /** Returns the total size (in bytes) of data in this cache. @@ -93,7 +93,7 @@ @return The total data size in bytes. */ -- (NSInteger)totalSize; +- (NSUInteger)totalSize; @end diff --git a/SDWebImage/SDDiskCache.m b/SDWebImage/SDDiskCache.m index ebf40fcf..539cd68b 100644 --- a/SDWebImage/SDDiskCache.m +++ b/SDWebImage/SDDiskCache.m @@ -203,7 +203,7 @@ return [self cachePathForKey:key inPath:self.diskCachePath]; } -- (NSInteger)totalSize { +- (NSUInteger)totalSize { NSUInteger size = 0; NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtPath:self.diskCachePath]; for (NSString *fileName in fileEnumerator) { @@ -214,7 +214,7 @@ return size; } -- (NSInteger)totalCount { +- (NSUInteger)totalCount { NSUInteger count = 0; NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtPath:self.diskCachePath]; count = fileEnumerator.allObjects.count; diff --git a/SDWebImage/SDImageCoder.h b/SDWebImage/SDImageCoder.h index 9084c6fb..36a78fb2 100644 --- a/SDWebImage/SDImageCoder.h +++ b/SDWebImage/SDImageCoder.h @@ -164,7 +164,7 @@ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderWebImageContext; @return The animated image data */ -- (nullable NSData *)animatedImageData; +@property (nonatomic, copy, readonly, nullable) NSData *animatedImageData; /** Total animated frame count. @@ -172,13 +172,13 @@ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderWebImageContext; @return Total animated frame count. */ -- (NSUInteger)animatedImageFrameCount; +@property (nonatomic, assign, readonly) NSUInteger animatedImageFrameCount; /** Animation loop count, 0 means infinite looping. @return Animation loop count */ -- (NSUInteger)animatedImageLoopCount; +@property (nonatomic, assign, readonly) NSUInteger animatedImageLoopCount; /** Returns the frame image from a specified index. @note The index maybe randomly if one image was set to different imageViews, keep it re-entrant. (It's not recommend to store the images into array because it's memory consuming) diff --git a/SDWebImage/SDImageTransformer.h b/SDWebImage/SDImageTransformer.h index a3e834ce..0a569ccc 100644 --- a/SDWebImage/SDImageTransformer.h +++ b/SDWebImage/SDImageTransformer.h @@ -32,7 +32,7 @@ FOUNDATION_EXPORT NSString * _Nullable SDTransformedKeyForKey(NSString * _Nullab @return The cache key to appended after the original cache key. Should not be nil. */ -- (nonnull NSString *)transformerKey; +@property (nonatomic, copy, readonly, nonnull) NSString *transformerKey; /** Transform the image to another image. diff --git a/SDWebImage/SDWebImageDownloaderOperation.h b/SDWebImage/SDWebImageDownloaderOperation.h index f7f9f07e..01b7ea6d 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.h +++ b/SDWebImage/SDWebImageDownloaderOperation.h @@ -38,15 +38,13 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification - (BOOL)cancel:(nullable id)token; -- (nullable NSURLRequest *)request; -- (nullable NSURLResponse *)response; +@property (strong, nonatomic, readonly, nullable) NSURLRequest *request; +@property (strong, nonatomic, readonly, nullable) NSURLResponse *response; @optional -- (nullable NSURLSessionTask *)dataTask; -- (nullable NSURLCredential *)credential; -- (void)setCredential:(nullable NSURLCredential *)credential; -- (double)minimumProgressInterval; -- (void)setMinimumProgressInterval:(double)minimumProgressInterval; +@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask; +@property (strong, nonatomic, nullable) NSURLCredential *credential; +@property (assign, nonatomic) double minimumProgressInterval; @end @@ -61,7 +59,7 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification /** * The response returned by the operation's task. */ -@property (strong, nonatomic, nullable, readonly) NSURLResponse *response; +@property (strong, nonatomic, readonly, nullable) NSURLResponse *response; /** * The operation's task @@ -73,7 +71,7 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification * * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. */ -@property (nonatomic, strong, nullable) NSURLCredential *credential; +@property (strong, nonatomic, nullable) NSURLCredential *credential; /** * The minimum interval about progress percent during network downloading. Which means the next progress callback and current progress callback's progress percent difference should be larger or equal to this value. However, the final finish download progress callback does not get effected. diff --git a/SDWebImage/SDWebImageIndicator.h b/SDWebImage/SDWebImageIndicator.h index aa62ca5f..9716dd90 100644 --- a/SDWebImage/SDWebImageIndicator.h +++ b/SDWebImage/SDWebImageIndicator.h @@ -20,7 +20,7 @@ @return The indicator view */ -- (nonnull UIView *)indicatorView; +@property (nonatomic, strong, readonly, nonnull) UIView *indicatorView; /** Start the animating for indicator. */ diff --git a/Tests/Tests/SDWebImageTestCache.m b/Tests/Tests/SDWebImageTestCache.m index da2a9935..1a92ec8f 100644 --- a/Tests/Tests/SDWebImageTestCache.m +++ b/Tests/Tests/SDWebImageTestCache.m @@ -91,11 +91,11 @@ [self.fileManager createFileAtPath:[self cachePathForKey:key] contents:data attributes:nil]; } -- (NSInteger)totalCount { +- (NSUInteger)totalCount { return [self.fileManager contentsOfDirectoryAtPath:self.cachePath error:nil].count; } -- (NSInteger)totalSize { +- (NSUInteger)totalSize { NSUInteger size = 0; for (NSString *fileName in [self.fileManager enumeratorAtPath:self.cachePath]) { NSString *filePath = [self.cachePath stringByAppendingPathComponent:fileName];