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`
This commit is contained in:
DreamPiggy 2018-07-24 14:11:57 +08:00 committed by Wu Zhong
parent fe2fede60f
commit 919751f2de
2 changed files with 16 additions and 9 deletions

View File

@ -10,15 +10,18 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "SDWebImageCompat.h" #import "SDWebImageCompat.h"
typedef NS_ENUM(NSInteger, SDImageFormat) { /**
SDImageFormatUndefined = -1, 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.
SDImageFormatJPEG = 0, For custom coder plugin, it can also extern the enum for supported format. See `SDImageCoder` for more detailed information.
SDImageFormatPNG, */
SDImageFormatGIF, typedef NSInteger SDImageFormat NS_TYPED_EXTENSIBLE_ENUM;
SDImageFormatTIFF, static const SDImageFormat SDImageFormatUndefined = -1;
SDImageFormatWebP, static const SDImageFormat SDImageFormatJPEG = 0;
SDImageFormatHEIC 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) @interface NSData (ImageContentType)

View File

@ -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. 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 @param format The image format
@return YES if this coder can encode the image, NO otherwise @return YES if this coder can encode the image, NO otherwise