From 919751f2de55ccc4f3d5361d7d78d7a4d10ff4a8 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 24 Jul 2018 14:11:57 +0800 Subject: [PATCH] Change SDImageFormat to use `NS_TYPED_EXTENSIBLE_ENUM` instead of fixed enum, to allow custom coder plugin extern the define (#2400) * Change SDImageFormat to use `NS_TYPED_EXTENSIBLE_ENUM` instead of fixed enum, to allow custom coder plugin extern the define * Update the comment and indent about `SDImageFormat` --- SDWebImage/NSData+ImageContentType.h | 21 ++++++++++++--------- SDWebImage/SDImageCoder.h | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/SDWebImage/NSData+ImageContentType.h b/SDWebImage/NSData+ImageContentType.h index 2a9f7e2b..c5970cb4 100644 --- a/SDWebImage/NSData+ImageContentType.h +++ b/SDWebImage/NSData+ImageContentType.h @@ -10,15 +10,18 @@ #import #import "SDWebImageCompat.h" -typedef NS_ENUM(NSInteger, SDImageFormat) { - SDImageFormatUndefined = -1, - SDImageFormatJPEG = 0, - SDImageFormatPNG, - SDImageFormatGIF, - SDImageFormatTIFF, - SDImageFormatWebP, - SDImageFormatHEIC -}; +/** + You can use switch case like normal enum. It's also recommended to add a default case. You should not assume anything about the raw value. + For custom coder plugin, it can also extern the enum for supported format. See `SDImageCoder` for more detailed information. + */ +typedef NSInteger SDImageFormat NS_TYPED_EXTENSIBLE_ENUM; +static const SDImageFormat SDImageFormatUndefined = -1; +static const SDImageFormat SDImageFormatJPEG = 0; +static const SDImageFormat SDImageFormatPNG = 1; +static const SDImageFormat SDImageFormatGIF = 2; +static const SDImageFormat SDImageFormatTIFF = 3; +static const SDImageFormat SDImageFormatWebP = 4; +static const SDImageFormat SDImageFormatHEIC = 5; @interface NSData (ImageContentType) diff --git a/SDWebImage/SDImageCoder.h b/SDWebImage/SDImageCoder.h index ebf151b2..d6c7a735 100644 --- a/SDWebImage/SDImageCoder.h +++ b/SDWebImage/SDImageCoder.h @@ -72,6 +72,10 @@ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeCompressio /** Returns YES if this coder can encode some image. Otherwise, it should be passed to another coder. + For custom coder which introduce new image format, you'd better define a new `SDImageFormat` using like this. If you're creating public coder plugin for new image format, also update `https://github.com/rs/SDWebImage/wiki/Coder-Plugin-List` to avoid same value been defined twice. + * @code + static const SDImageFormat SDImageFormatHEIF = 10; + * @endcode @param format The image format @return YES if this coder can encode the image, NO otherwise