Use UIImage.class for conformsToSelector detect, which fix the current Xcode 11 Beta5 's runtime behavior of UIKit for macOS

This commit is contained in:
DreamPiggy 2019-08-12 20:55:07 +08:00
parent 77e54697c5
commit 054c5186b8
4 changed files with 9 additions and 7 deletions

View File

@ -203,7 +203,7 @@ static NSUInteger SDDeviceFreeMemory() {
// We need call super method to keep function. This will impliedly call `setNeedsDisplay`. But we have no way to avoid this when using animated image. So we call `setNeedsDisplay` again at the end.
super.image = image;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
NSUInteger animatedImageFrameCount = ((UIImage<SDAnimatedImage> *)image).animatedImageFrameCount;
// Check the frame count
if (animatedImageFrameCount <= 1) {
@ -536,9 +536,11 @@ static NSUInteger SDDeviceFreeMemory() {
// Early return
return;
}
if ([image conformsToProtocol:@protocol(SDAnimatedImage)] && image.sd_isIncremental) {
// We must use `image.class conformsToProtocol:` instead of `image conformsToProtocol:` here
// Because UIKit on macOS, using internal hard-coded override method, which returns NO
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)] && image.sd_isIncremental) {
UIImage *previousImage = self.image;
if ([previousImage conformsToProtocol:@protocol(SDAnimatedImage)] && previousImage.sd_isIncremental) {
if ([previousImage.class conformsToProtocol:@protocol(SDAnimatedImage)] && previousImage.sd_isIncremental) {
NSData *previousData = [((UIImage<SDAnimatedImage> *)previousImage) animatedImageData];
NSData *currentData = [((UIImage<SDAnimatedImage> *)image) animatedImageData];
// Check whether to use progressive rendering or not

View File

@ -47,7 +47,7 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {

View File

@ -61,7 +61,7 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {
@ -143,7 +143,7 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
}
if (image) {
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
if ([image.class conformsToProtocol:@protocol(SDAnimatedImage)]) {
// `SDAnimatedImage` do not decode
shouldDecode = NO;
} else if (image.sd_isAnimated) {

View File

@ -264,7 +264,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
// Progressive image may be nil when download data is not enough
if (image) {
expect(image.sd_isIncremental).beTruthy();
expect([image conformsToProtocol:@protocol(SDAnimatedImage)]).beTruthy();
expect([image.class conformsToProtocol:@protocol(SDAnimatedImage)]).beTruthy();
BOOL isProgressive = imageView.isProgressive;
expect(isProgressive).equal(YES);
}