From b6e108a5b18bc877bee0b01eabb270505f7e2554 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 13 Jan 2018 17:27:42 +0800 Subject: [PATCH] Rename `NSImage+WebCache` to `NSImage+Addtions`. Add helper methods, use property based API, which more suitable for Swift --- SDWebImage.xcodeproj/project.pbxproj | 26 +++++++---- SDWebImage/NSImage+Additions.h | 25 ++++++++++ SDWebImage/NSImage+Additions.m | 53 ++++++++++++++++++++++ SDWebImage/NSImage+WebCache.h | 20 -------- SDWebImage/NSImage+WebCache.m | 28 ------------ SDWebImage/SDImageCache.m | 2 +- SDWebImage/SDWebImageCoderHelper.m | 4 +- SDWebImage/SDWebImageCompat.m | 1 + SDWebImage/SDWebImageDownloaderOperation.m | 2 +- SDWebImage/SDWebImageGIFCoder.m | 2 +- SDWebImage/SDWebImageImageIOCoder.m | 2 +- SDWebImage/SDWebImageManager.m | 2 +- SDWebImage/SDWebImageWebPCoder.m | 2 +- SDWebImage/UIImage+WebCache.m | 51 ++++++++++++--------- WebImage/SDWebImage.h | 2 +- 15 files changed, 136 insertions(+), 86 deletions(-) create mode 100644 SDWebImage/NSImage+Additions.h create mode 100644 SDWebImage/NSImage+Additions.m delete mode 100644 SDWebImage/NSImage+WebCache.h delete mode 100644 SDWebImage/NSImage+WebCache.m diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 4618c0bb..98fce072 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -97,6 +97,11 @@ 321E60C71F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; 321E60C81F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; 321E60C91F38E91700405457 /* UIImage+ForceDecode.m in Sources */ = {isa = PBXBuildFile; fileRef = 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */; }; + 3237F9E820161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9E920161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EA20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EB20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; + 3237F9EC20161AE000A88143 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; 323F8B3E1F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; 323F8B3F1F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; 323F8B401F38EF770092B609 /* alpha_enc.c in Sources */ = {isa = PBXBuildFile; fileRef = 323F8B131F38EF770092B609 /* alpha_enc.c */; }; @@ -488,8 +493,8 @@ 4397D2EA1D0DDD8C00BB2784 /* UIImage+GIF.h in Headers */ = {isa = PBXBuildFile; fileRef = A18A6CC5172DC28500419892 /* UIImage+GIF.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2EB1D0DDD8C00BB2784 /* NSData+ImageContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D5B9140188EE8DD006D06BD /* NSData+ImageContentType.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2ED1D0DDD8C00BB2784 /* mux_types.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577CC91998E60B007367ED /* mux_types.h */; }; - 4397D2F61D0DE2DF00BB2784 /* NSImage+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4397D2F71D0DE2DF00BB2784 /* NSImage+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */; }; + 4397D2F61D0DE2DF00BB2784 /* NSImage+Additions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4397D2F71D0DE2DF00BB2784 /* NSImage+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */; }; 4397D2F81D0DF44200BB2784 /* MKAnnotationView+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4397D2F91D0DF44A00BB2784 /* MKAnnotationView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */; }; 43A62A1B1D0E0A800089D7DD /* decode.h in Headers */ = {isa = PBXBuildFile; fileRef = DA577CC41998E60B007367ED /* decode.h */; }; @@ -1341,8 +1346,8 @@ 4369C2751D9807EC007E863A /* UIView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIView+WebCache.h"; path = "SDWebImage/UIView+WebCache.h"; sourceTree = ""; }; 4369C2761D9807EC007E863A /* UIView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIView+WebCache.m"; path = "SDWebImage/UIView+WebCache.m"; sourceTree = ""; }; 4397D2F21D0DDD8C00BB2784 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSImage+WebCache.h"; path = "SDWebImage/NSImage+WebCache.h"; sourceTree = ""; }; - 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSImage+WebCache.m"; path = "SDWebImage/NSImage+WebCache.m"; sourceTree = ""; }; + 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+Additions.h"; sourceTree = ""; }; + 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+Additions.m"; sourceTree = ""; }; 43A918621D8308FE00B3925F /* SDImageCacheConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCacheConfig.h; sourceTree = ""; }; 43A918631D8308FE00B3925F /* SDImageCacheConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheConfig.m; sourceTree = ""; }; 43C892981D9D6DD70022038D /* anim_decode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = anim_decode.c; sourceTree = ""; }; @@ -1640,8 +1645,6 @@ children = ( 329A18571FFF5DFD008C9A2F /* UIImage+WebCache.h */, 329A18581FFF5DFD008C9A2F /* UIImage+WebCache.m */, - 4397D2F41D0DE2DF00BB2784 /* NSImage+WebCache.h */, - 4397D2F51D0DE2DF00BB2784 /* NSImage+WebCache.m */, 535699B415113E7300A4C397 /* MKAnnotationView+WebCache.h */, 535699B515113E7300A4C397 /* MKAnnotationView+WebCache.m */, 53922D93148C56230056699D /* UIButton+WebCache.h */, @@ -1778,6 +1781,8 @@ 53EDFB921762547C00698166 /* UIImage+WebP.m */, 321E60BC1F38E91700405457 /* UIImage+ForceDecode.h */, 321E60BD1F38E91700405457 /* UIImage+ForceDecode.m */, + 4397D2F41D0DE2DF00BB2784 /* NSImage+Additions.h */, + 4397D2F51D0DE2DF00BB2784 /* NSImage+Additions.m */, AB615301192DA24600A2D8E9 /* UIView+WebCacheOperation.h */, AB615302192DA24600A2D8E9 /* UIView+WebCacheOperation.m */, ); @@ -2280,7 +2285,7 @@ 80377E661F2F66A800F89830 /* neon.h in Headers */, 4397D2DB1D0DDD8C00BB2784 /* UIImage+MultiFormat.h in Headers */, 4397D2DC1D0DDD8C00BB2784 /* SDWebImageOperation.h in Headers */, - 4397D2F61D0DE2DF00BB2784 /* NSImage+WebCache.h in Headers */, + 4397D2F61D0DE2DF00BB2784 /* NSImage+Additions.h in Headers */, 4397D2E11D0DDD8C00BB2784 /* SDWebImageDownloader.h in Headers */, 323F8BFB1F38EF770092B609 /* animi.h in Headers */, 4397D2E31D0DDD8C00BB2784 /* MKAnnotationView+WebCache.h in Headers */, @@ -2722,6 +2727,7 @@ 80377C4E1F2F666300F89830 /* filters_utils.c in Sources */, 321E60B91F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 80377DEB1F2F66A700F89830 /* yuv.c in Sources */, + 3237F9E920161AE000A88143 /* NSImage+Additions.m in Sources */, 00733A551BC4880000A5A117 /* SDWebImageDownloader.m in Sources */, 80377EB71F2F66D400F89830 /* alpha_dec.c in Sources */, 80377DC61F2F66A700F89830 /* enc.c in Sources */, @@ -2922,6 +2928,7 @@ 80377D1F1F2F66A700F89830 /* alpha_processing_neon.c in Sources */, 4314D1401D0E0E3B004B36C9 /* UIImageView+WebCache.m in Sources */, 43A9186C1D8308FE00B3925F /* SDImageCacheConfig.m in Sources */, + 3237F9EC20161AE000A88143 /* NSImage+Additions.m in Sources */, 4314D1411D0E0E3B004B36C9 /* SDWebImageDownloaderOperation.m in Sources */, 80377D561F2F66A700F89830 /* rescaler_neon.c in Sources */, 80377D551F2F66A700F89830 /* rescaler_msa.c in Sources */, @@ -3066,6 +3073,7 @@ 323F8C0C1F38EF770092B609 /* muxedit.c in Sources */, 80377DEE1F2F66A800F89830 /* alpha_processing_neon.c in Sources */, 43C892A41D9D6DDD0022038D /* demux.c in Sources */, + 3237F9EA20161AE000A88143 /* NSImage+Additions.m in Sources */, 431BB6B61D06D2C1006A3455 /* UIImage+WebP.m in Sources */, 80377E251F2F66A800F89830 /* rescaler_neon.c in Sources */, 80377E241F2F66A800F89830 /* rescaler_msa.c in Sources */, @@ -3125,7 +3133,7 @@ 321E60911F38E8C800405457 /* SDWebImageCoder.m in Sources */, 80377C8A1F2F666400F89830 /* quant_levels_utils.c in Sources */, 4397D27F1D0DDD8C00BB2784 /* UIImage+WebP.m in Sources */, - 4397D2F71D0DE2DF00BB2784 /* NSImage+WebCache.m in Sources */, + 4397D2F71D0DE2DF00BB2784 /* NSImage+Additions.m in Sources */, 80377E751F2F66A800F89830 /* yuv.c in Sources */, 43C892A01D9D6DDA0022038D /* anim_decode.c in Sources */, 80377E4A1F2F66A800F89830 /* enc_mips_dsp_r2.c in Sources */, @@ -3304,6 +3312,7 @@ 80377DA61F2F66A700F89830 /* yuv.c in Sources */, 321E60B81F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 43CE757A1CFE9427006C64D0 /* FLAnimatedImage.m in Sources */, + 3237F9E820161AE000A88143 /* NSImage+Additions.m in Sources */, 80377D811F2F66A700F89830 /* enc.c in Sources */, 80377EA71F2F66D400F89830 /* alpha_dec.c in Sources */, 80377D8F1F2F66A700F89830 /* lossless_mips_dsp_r2.c in Sources */, @@ -3452,6 +3461,7 @@ 321E60B61F38E90100405457 /* SDWebImageWebPCoder.m in Sources */, 43CE75791CFE9427006C64D0 /* FLAnimatedImage.m in Sources */, 80377CF71F2F66A100F89830 /* enc.c in Sources */, + 3237F9EB20161AE000A88143 /* NSImage+Additions.m in Sources */, 80377E871F2F66D000F89830 /* alpha_dec.c in Sources */, 80377D051F2F66A100F89830 /* lossless_mips_dsp_r2.c in Sources */, 80377C0A1F2F665300F89830 /* random_utils.c in Sources */, diff --git a/SDWebImage/NSImage+Additions.h b/SDWebImage/NSImage+Additions.h new file mode 100644 index 00000000..3a78ce91 --- /dev/null +++ b/SDWebImage/NSImage+Additions.h @@ -0,0 +1,25 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" + +// This category is provided to easily write cross-platform code. For common usage, see `UIImage+WebCache`. + +#if SD_MAC + +@interface NSImage (Additions) + +@property (nonatomic, readonly, nullable) CGImageRef CGImage; +@property (nonatomic, readonly, nullable) NSArray *images; +@property (nonatomic, readonly) CGFloat scale; + +- (nonnull instancetype)initWithCGImage:(nonnull CGImageRef)cgImage scale:(CGFloat)scale; + +@end + +#endif diff --git a/SDWebImage/NSImage+Additions.m b/SDWebImage/NSImage+Additions.m new file mode 100644 index 00000000..466a9444 --- /dev/null +++ b/SDWebImage/NSImage+Additions.m @@ -0,0 +1,53 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "NSImage+Additions.h" + +#if SD_MAC + +@implementation NSImage (Additions) + +- (CGImageRef)CGImage { + NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); + CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil]; + return cgImage; +} + +- (NSArray *)images { + return nil; +} + +- (CGFloat)scale { + CGFloat scale = 1; + NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); + NSImageRep *rep = [self bestRepresentationForRect:imageRect context:NULL hints:nil]; + NSInteger pixelsWide = rep.pixelsWide; + CGFloat width = rep.size.width; + if (width > 0) { + scale = pixelsWide / width; + } + return scale; +} + +- (instancetype)initWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale { + NSSize size; + if (cgImage && scale > 0) { + NSInteger pixelsWide = CGImageGetWidth(cgImage); + NSInteger pixelsHigh = CGImageGetHeight(cgImage); + CGFloat width = pixelsWide / scale; + CGFloat height = pixelsHigh / scale; + size = NSMakeSize(width, height); + } else { + size = NSZeroSize; + } + return [self initWithCGImage:cgImage size:size]; +} + +@end + +#endif diff --git a/SDWebImage/NSImage+WebCache.h b/SDWebImage/NSImage+WebCache.h deleted file mode 100644 index 1f7b888d..00000000 --- a/SDWebImage/NSImage+WebCache.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This file is part of the SDWebImage package. - * (c) Olivier Poitrey - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -#import "SDWebImageCompat.h" - -#if SD_MAC - -@interface NSImage (Additions) - -- (nullable CGImageRef)CGImage; -- (nullable NSArray *)images; - -@end - -#endif diff --git a/SDWebImage/NSImage+WebCache.m b/SDWebImage/NSImage+WebCache.m deleted file mode 100644 index b42785ea..00000000 --- a/SDWebImage/NSImage+WebCache.m +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of the SDWebImage package. - * (c) Olivier Poitrey - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -#import "NSImage+WebCache.h" - -#if SD_MAC - -@implementation NSImage (Additions) - -- (CGImageRef)CGImage { - NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); - CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil]; - return cgImage; -} - -- (NSArray *)images { - return nil; -} - -@end - -#endif - diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 42335732..4c027083 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -8,7 +8,7 @@ #import "SDImageCache.h" #import -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "SDWebImageCodersManager.h" static void * SDImageCacheContext = &SDImageCacheContext; diff --git a/SDWebImage/SDWebImageCoderHelper.m b/SDWebImage/SDWebImageCoderHelper.m index b2b651a2..2ffcfd9a 100644 --- a/SDWebImage/SDWebImageCoderHelper.m +++ b/SDWebImage/SDWebImageCoderHelper.m @@ -8,8 +8,8 @@ #import "SDWebImageCoderHelper.h" #import "SDWebImageFrame.h" -#import "UIImage+MultiFormat.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" +#import "NSData+ImageContentType.h" #import @implementation SDWebImageCoderHelper diff --git a/SDWebImage/SDWebImageCompat.m b/SDWebImage/SDWebImageCompat.m index eff574ac..b3377e6a 100644 --- a/SDWebImage/SDWebImageCompat.m +++ b/SDWebImage/SDWebImageCompat.m @@ -8,6 +8,7 @@ #import "SDWebImageCompat.h" #import "UIImage+WebCache.h" +#import "NSImage+Additions.h" #if !__has_feature(objc_arc) #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 553b0e95..cffb1a86 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -8,7 +8,7 @@ #import "SDWebImageDownloaderOperation.h" #import "SDWebImageManager.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "SDWebImageCodersManager.h" NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index e2705f87..b8c9c4b2 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -7,7 +7,7 @@ */ #import "SDWebImageGIFCoder.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "UIImage+WebCache.h" #import #import "NSData+ImageContentType.h" diff --git a/SDWebImage/SDWebImageImageIOCoder.m b/SDWebImage/SDWebImageImageIOCoder.m index baf3cfdf..570e2a11 100644 --- a/SDWebImage/SDWebImageImageIOCoder.m +++ b/SDWebImage/SDWebImageImageIOCoder.m @@ -8,7 +8,7 @@ #import "SDWebImageImageIOCoder.h" #import "SDWebImageCoderHelper.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import #import "NSData+ImageContentType.h" diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 36ab073b..645bf506 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -7,7 +7,7 @@ */ #import "SDWebImageManager.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import @interface SDWebImageCombinedOperation : NSObject diff --git a/SDWebImage/SDWebImageWebPCoder.m b/SDWebImage/SDWebImageWebPCoder.m index d80ff445..3f68c1c5 100644 --- a/SDWebImage/SDWebImageWebPCoder.m +++ b/SDWebImage/SDWebImageWebPCoder.m @@ -10,7 +10,7 @@ #import "SDWebImageWebPCoder.h" #import "SDWebImageCoderHelper.h" -#import "NSImage+WebCache.h" +#import "NSImage+Additions.h" #import "UIImage+WebCache.h" #if __has_include() && __has_include() && __has_include() && __has_include() #import diff --git a/SDWebImage/UIImage+WebCache.m b/SDWebImage/UIImage+WebCache.m index ed5c337f..60d3e2f7 100644 --- a/SDWebImage/UIImage+WebCache.m +++ b/SDWebImage/UIImage+WebCache.m @@ -7,11 +7,39 @@ */ #import "UIImage+WebCache.h" + +#if SD_UIKIT + #import "objc/runtime.h" @implementation UIImage (WebCache) +- (NSUInteger)sd_imageLoopCount { + NSUInteger imageLoopCount = 0; + NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); + if ([value isKindOfClass:[NSNumber class]]) { + imageLoopCount = value.unsignedIntegerValue; + } + return imageLoopCount; +} + +- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { + NSNumber *value = @(sd_imageLoopCount); + objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)sd_isAnimated { + return (self.images != nil); +} + +@end + +#endif + #if SD_MAC + +@implementation NSImage (WebCache) + - (NSUInteger)sd_imageLoopCount { NSUInteger imageLoopCount = 0; for (NSImageRep *rep in self.representations) { @@ -47,25 +75,6 @@ return isGIF; } -#else - -- (NSUInteger)sd_imageLoopCount { - NSUInteger imageLoopCount = 0; - NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount)); - if ([value isKindOfClass:[NSNumber class]]) { - imageLoopCount = value.unsignedIntegerValue; - } - return imageLoopCount; -} - -- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount { - NSNumber *value = @(sd_imageLoopCount); - objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (BOOL)sd_isAnimated { - return (self.images != nil); -} -#endif - @end + +#endif diff --git a/WebImage/SDWebImage.h b/WebImage/SDWebImage.h index dd6f8190..22258eba 100644 --- a/WebImage/SDWebImage.h +++ b/WebImage/SDWebImage.h @@ -53,7 +53,7 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[]; #import #if SD_MAC - #import + #import #endif #if SD_UIKIT