diff --git a/SDWebImage/Core/SDAnimatedImageView.m b/SDWebImage/Core/SDAnimatedImageView.m index e9734383..71ee7e34 100644 --- a/SDWebImage/Core/SDAnimatedImageView.m +++ b/SDWebImage/Core/SDAnimatedImageView.m @@ -470,10 +470,10 @@ // NSImageView use a subview. We need this subview's layer for actual rendering. // Why using this design may because of properties like `imageAlignment` and `imageScaling`, which it's not available for UIImageView.contentMode (it's impossible to align left and keep aspect ratio at the same time) - (NSView *)imageView { - NSImageView *imageView = imageView = objc_getAssociatedObject(self, NSSelectorFromString(@"_imageView")); + NSImageView *imageView = imageView = objc_getAssociatedObject(self, SD_SEL_SPI(imageView)); if (!imageView) { // macOS 10.14 - imageView = objc_getAssociatedObject(self, NSSelectorFromString(@"_imageSubview")); + imageView = objc_getAssociatedObject(self, SD_SEL_SPI(imageSubview)); } return imageView; } diff --git a/SDWebImage/Core/UIImage+Metadata.m b/SDWebImage/Core/UIImage+Metadata.m index 2d24c4e2..09724236 100644 --- a/SDWebImage/Core/UIImage+Metadata.m +++ b/SDWebImage/Core/UIImage+Metadata.m @@ -8,6 +8,7 @@ #import "UIImage+Metadata.h" #import "NSImage+Compatibility.h" +#import "SDInternalMacros.h" #import "objc/runtime.h" @implementation UIImage (Metadata) @@ -42,14 +43,14 @@ return YES; } // SVG - SEL SVGSelector = NSSelectorFromString(@"_CGSVGDocument"); + SEL SVGSelector = SD_SEL_SPI(CGSVGDocument); if ([self respondsToSelector:SVGSelector] && [self performSelector:SVGSelector]) { return YES; } } if (@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)) { // PDF - SEL PDFSelector = NSSelectorFromString(@"_CGPDFPage"); + SEL PDFSelector = SD_SEL_SPI(CGPDFPage); if ([self respondsToSelector:PDFSelector] && [self performSelector:PDFSelector]) { return YES; } diff --git a/SDWebImage/Private/SDInternalMacros.h b/SDWebImage/Private/SDInternalMacros.h index 837d77b0..aad700f8 100644 --- a/SDWebImage/Private/SDInternalMacros.h +++ b/SDWebImage/Private/SDInternalMacros.h @@ -21,6 +21,18 @@ #define SD_OPTIONS_CONTAINS(options, value) (((options) & (value)) == (value)) #endif +#ifndef SD_CSTRING +#define SD_CSTRING(str) #str +#endif + +#ifndef SD_NSSTRING +#define SD_NSSTRING(str) @(SD_CSTRING(str)) +#endif + +#ifndef SD_SEL_SPI +#define SD_SEL_SPI(name) NSSelectorFromString([NSString stringWithFormat:@"_%@", SD_NSSTRING(name)]) +#endif + #ifndef weakify #define weakify(...) \ sd_keywordify \