Browse Source

swift api compatibility

ibireme 9 years ago
parent
commit
6a5aa7297d

+ 17 - 14
YYWebImage/Cache/YYCache.h

@@ -27,6 +27,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
 #import "YYKVStorage.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 
 /**
@@ -56,17 +57,17 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
      read and write to this directory.
  @result A new cache object, or nil if an error occurs.
  */
-- (instancetype)initWithName:(NSString *)name;
+- (nullable instancetype)initWithName:(NSString *)name;
 
 /**
- Create a new instance with the specified name.
+ Create a new instance with the specified path.
  Multiple instances with the same name will make the cache unstable.
  
  @param path  Full path of a directory in which the cache will write data.
      Once initialized you should not read and write to this directory.
  @result A new cache object, or nil if an error occurs.
  */
-- (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
 
 /**
  Convenience Initializers
@@ -78,18 +79,18 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
      read and write to this directory.
  @result A new cache object, or nil if an error occurs.
  */
-+ (instancetype)cacheWithName:(NSString *)name;
++ (nullable instancetype)cacheWithName:(NSString *)name;
 
 /**
  Convenience Initializers
- Create a new instance with the specified name.
+ Create a new instance with the specified path.
  Multiple instances with the same name will make the cache unstable.
  
  @param path  Full path of a directory in which the cache will write data.
      Once initialized you should not read and write to this directory.
  @result A new cache object, or nil if an error occurs.
  */
-+ (instancetype)cacheWithPath:(NSString *)path;
++ (nullable instancetype)cacheWithPath:(NSString *)path;
 
 - (instancetype)init UNAVAILABLE_ATTRIBUTE;
 + (instancetype)new UNAVAILABLE_ATTRIBUTE;
@@ -116,7 +117,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param key   A string identifying the value. If nil, just return NO.
  @param block A block which will be invoked in background queue when finished.
  */
-- (void)containsObjectForKey:(NSString *)key withBlock:(void(^)(NSString *key, BOOL contains))block;
+- (void)containsObjectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key, BOOL contains))block;
 
 /**
  Returns the value associated with a given key.
@@ -125,7 +126,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param key A string identifying the value. If nil, just return nil.
  @return The value associated with key, or nil if no value is associated with key.
  */
-- (id<NSCoding>)objectForKey:(NSString *)key;
+- (nullable id<NSCoding>)objectForKey:(NSString *)key;
 
 /**
  Returns the value associated with a given key.
@@ -135,7 +136,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param key A string identifying the value. If nil, just return nil.
  @param block A block which will be invoked in background queue when finished.
  */
-- (void)objectForKey:(NSString *)key withBlock:(void(^)(NSString *key, id<NSCoding> object))block;
+- (void)objectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key, id<NSCoding> object))block;
 
 /**
  Sets the value of the specified key in the cache.
@@ -144,7 +145,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
  @param key    The key with which to associate the value. If nil, this method has no effect.
  */
-- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key;
+- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
 
 /**
  Sets the value of the specified key in the cache.
@@ -154,7 +155,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
  @param block  A block which will be invoked in background queue when finished.
  */
-- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key withBlock:(void(^)(void))block;
+- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key withBlock:(nullable void(^)(void))block;
 
 /**
  Removes the value of the specified key in the cache.
@@ -172,7 +173,7 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param key The key identifying the value to be removed. If nil, this method has no effect.
  @param block  A block which will be invoked in background queue when finished.
  */
-- (void)removeObjectForKey:(NSString *)key withBlock:(void(^)(NSString *key))block;
+- (void)removeObjectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key))block;
 
 /**
  Empties the cache.
@@ -197,7 +198,9 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  @param progress This block will be invoked during removing, pass nil to ignore.
  @param end      This block will be invoked at the end, pass nil to ignore.
  */
-- (void)removeAllObjectsWithProgressBlock:(void(^)(int removedCount, int totalCount))progress
-                                 endBlock:(void(^)(BOOL error))end;
+- (void)removeAllObjectsWithProgressBlock:(nullable void(^)(int removedCount, int totalCount))progress
+                                 endBlock:(nullable void(^)(BOOL error))end;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 1 - 1
YYWebImage/Cache/YYCache.m

@@ -17,7 +17,7 @@
 
 - (instancetype) init {
     NSLog(@"Use \"initWithName\" or \"initWithPath\" to create YYCache instance.");
-    return [self initWithPath:nil];
+    return [self initWithPath:@""];
 }
 
 - (instancetype)initWithName:(NSString *)name {

+ 24 - 20
YYWebImage/Cache/YYDiskCache.h

@@ -11,6 +11,8 @@
 
 #import <Foundation/Foundation.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  YYDiskCache is a thread-safe cache that stores key-value pairs backed by SQLite
  and file system (similar to NSURLCache's disk cache).
@@ -34,7 +36,7 @@
 ///=============================================================================
 
 /** The name of the cache. Default is nil. */
-@property (copy) NSString *name;
+@property (nullable, copy) NSString *name;
 
 /** The path of the cache (read-only). */
 @property (readonly) NSString *path;
@@ -57,7 +59,7 @@
  
  The default value is nil.
  */
-@property (copy) NSData *(^customArchiveBlock)(id object);
+@property (nullable, copy) NSData *(^customArchiveBlock)(id object);
 
 /**
  If this block is not nil, then the block will be used to unarchive object instead
@@ -66,7 +68,7 @@
  
  The default value is nil.
  */
-@property (copy) id (^customUnarchiveBlock)(NSData *data);
+@property (nullable, copy) id (^customUnarchiveBlock)(NSData *data);
 
 /**
  When an object needs to be saved as a file, this block will be invoked to generate
@@ -75,7 +77,7 @@
  
  The default value is nil.
  */
-@property (copy) NSString *(^customFilenameBlock)(NSString *key);
+@property (nullable, copy) NSString *(^customFileNameBlock)(NSString *key);
 
 
 
@@ -91,7 +93,7 @@
  This is not a strict limit — if the cache goes over the limit, some objects in the
  cache could be evicted later in background queue.
  */
-@property (assign) NSUInteger countLimit;
+@property NSUInteger countLimit;
 
 /**
  The maximum total cost that the cache can hold before it starts evicting objects.
@@ -100,7 +102,7 @@
  This is not a strict limit — if the cache goes over the limit, some objects in the
  cache could be evicted later in background queue.
  */
-@property (assign) NSUInteger costLimit;
+@property NSUInteger costLimit;
 
 /**
  The maximum expiry time of objects in cache.
@@ -109,7 +111,7 @@
  This is not a strict limit — if an object goes over the limit, the objects could
  be evicted later in background queue.
  */
-@property (assign) NSTimeInterval ageLimit;
+@property NSTimeInterval ageLimit;
 
 /**
  The minimum free disk space (in bytes) which the cache should kept.
@@ -119,7 +121,7 @@
  to free some disk space. This is not a strict limit—if the free disk space goes
  over the limit, the objects could be evicted later in background queue.
  */
-@property (assign) NSUInteger freeDiskSpaceLimit;
+@property NSUInteger freeDiskSpaceLimit;
 
 /**
  The auto trim check time interval in seconds. Default is 60 (1 minute).
@@ -127,7 +129,7 @@
  @discussion The cache holds an internal timer to check whether the cache reaches
  its limits, and if the limit is reached, it begins to evict objects.
  */
-@property (assign) NSTimeInterval autoTrimInterval;
+@property NSTimeInterval autoTrimInterval;
 
 
 #pragma mark - Initializer
@@ -148,7 +150,7 @@
  @warning If the cache instance for the specified path already exists in memory,
      this method will return it directly, instead of creating a new instance.
  */
-- (instancetype)initWithPath:(NSString *)path;
+- (nullable instancetype)initWithPath:(NSString *)path;
 
 /**
  The designated initializer.
@@ -168,8 +170,8 @@
  @warning If the cache instance for the specified path already exists in memory,
      this method will return it directly, instead of creating a new instance.
  */
-- (instancetype)initWithPath:(NSString *)path
-             inlineThreshold:(NSUInteger)threshold NS_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithPath:(NSString *)path
+                      inlineThreshold:(NSUInteger)threshold NS_DESIGNATED_INITIALIZER;
 
 
 #pragma mark - Access Methods
@@ -203,7 +205,7 @@
  @param key A string identifying the value. If nil, just return nil.
  @return The value associated with key, or nil if no value is associated with key.
  */
-- (id<NSCoding>)objectForKey:(NSString *)key;
+- (nullable id<NSCoding>)objectForKey:(NSString *)key;
 
 /**
  Returns the value associated with a given key.
@@ -213,7 +215,7 @@
  @param key A string identifying the value. If nil, just return nil.
  @param block A block which will be invoked in background queue when finished.
  */
-- (void)objectForKey:(NSString *)key withBlock:(void(^)(NSString *key, id<NSCoding> object))block;
+- (void)objectForKey:(NSString *)key withBlock:(void(^)(NSString *key, id<NSCoding> _Nullable object))block;
 
 /**
  Sets the value of the specified key in the cache.
@@ -222,7 +224,7 @@
  @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
  @param key    The key with which to associate the value. If nil, this method has no effect.
  */
-- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key;
+- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
 
 /**
  Sets the value of the specified key in the cache.
@@ -232,7 +234,7 @@
  @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
  @param block  A block which will be invoked in background queue when finished.
  */
-- (void)setObject:(id<NSCoding>)object forKey:(NSString *)key withBlock:(void(^)(void))block;
+- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key withBlock:(void(^)(void))block;
 
 /**
  Removes the value of the specified key in the cache.
@@ -275,8 +277,8 @@
  @param progress This block will be invoked during removing, pass nil to ignore.
  @param end      This block will be invoked at the end, pass nil to ignore.
  */
-- (void)removeAllObjectsWithProgressBlock:(void(^)(int removedCount, int totalCount))progress
-                                 endBlock:(void(^)(BOOL error))end;
+- (void)removeAllObjectsWithProgressBlock:(nullable void(^)(int removedCount, int totalCount))progress
+                                 endBlock:(nullable void(^)(BOOL error))end;
 
 
 /**
@@ -387,7 +389,7 @@
  @param object An object.
  @return The extended data.
  */
-+ (NSData *)getExtendedDataFromObject:(id)object;
++ (nullable NSData *)getExtendedDataFromObject:(id)object;
 
 /**
  Set extended data to an object.
@@ -399,6 +401,8 @@
  @param extendedData The extended data (pass nil to remove).
  @param object       The object.
  */
-+ (void)setExtendedData:(NSData *)extendedData toObject:(id)object;
++ (void)setExtendedData:(nullable NSData *)extendedData toObject:(id)object;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 2 - 2
YYWebImage/Cache/YYDiskCache.m

@@ -144,7 +144,7 @@ static void _YYDiskCacheSetGlobal(YYDiskCache *cache) {
 
 - (NSString *)_filenameForKey:(NSString *)key {
     NSString *filename = nil;
-    if (_customFilenameBlock) filename = _customFilenameBlock(key);
+    if (_customFileNameBlock) filename = _customFileNameBlock(key);
     if (!filename) filename = _YYNSStringMD5(key);
     return filename;
 }
@@ -153,7 +153,7 @@ static void _YYDiskCacheSetGlobal(YYDiskCache *cache) {
 
 - (instancetype)init {
     @throw [NSException exceptionWithName:@"YYDiskCache init error" reason:@"YYDiskCache must be initialized with a path. Use 'initWithPath:' or 'initWithPath:inlineThreshold:' instead." userInfo:nil];
-    return [self initWithPath:nil inlineThreshold:0];
+    return [self initWithPath:@"" inlineThreshold:0];
 }
 
 - (instancetype)initWithPath:(NSString *)path {

+ 24 - 20
YYWebImage/Cache/YYKVStorage.h

@@ -11,18 +11,20 @@
 
 #import <Foundation/Foundation.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  YYKVStorageItem is used by `YYKVStorage` to store key-value pair and meta data.
  Typically, you should not use this class directly.
  */
 @interface YYKVStorageItem : NSObject
-@property (nonatomic, strong) NSString *key;        ///< key
-@property (nonatomic, strong) NSData *value;        ///< value
-@property (nonatomic, strong) NSString *filename;   ///< filename (nil if inline)
-@property (nonatomic, assign) int size;             ///< value's size in bytes
-@property (nonatomic, assign) int modTime;          ///< modification unix timestamp
-@property (nonatomic, assign) int accessTime;       ///< last access unix timestamp
-@property (nonatomic, strong) NSData *extendedData; ///< extended data (nil if no extended data)
+@property (nonatomic, strong) NSString *key;                ///< key
+@property (nonatomic, strong) NSData *value;                ///< value
+@property (nullable, nonatomic, strong) NSString *filename; ///< filename (nil if inline)
+@property (nonatomic) int size;                             ///< value's size in bytes
+@property (nonatomic) int modTime;                          ///< modification unix timestamp
+@property (nonatomic) int accessTime;                       ///< last access unix timestamp
+@property (nullable, nonatomic, strong) NSData *extendedData; ///< extended data (nil if no extended data)
 @end
 
 /**
@@ -80,7 +82,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
 
 @property (nonatomic, readonly) NSString *path;        ///< The path of this storage.
 @property (nonatomic, readonly) YYKVStorageType type;  ///< The type of this storage.
-@property (nonatomic, assign) BOOL errorLogsEnabled;   ///< Set `YES` to enable error logs for debug.
+@property (nonatomic) BOOL errorLogsEnabled;           ///< Set `YES` to enable error logs for debug.
 
 #pragma mark - Initializer
 ///=============================================================================
@@ -100,7 +102,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @return  A new storage object, or nil if an error occurs.
  @warning Multiple instances with the same path will make the storage unstable.
  */
-- (instancetype)initWithPath:(NSString *)path type:(YYKVStorageType)type NS_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithPath:(NSString *)path type:(YYKVStorageType)type NS_DESIGNATED_INITIALIZER;
 
 
 #pragma mark - Save Items
@@ -155,8 +157,8 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  */
 - (BOOL)saveItemWithKey:(NSString *)key
                   value:(NSData *)value
-               filename:(NSString *)filename
-           extendedData:(NSData *)extendedData;
+               filename:(nullable NSString *)filename
+           extendedData:(nullable NSData *)extendedData;
 
 #pragma mark - Remove Items
 ///=============================================================================
@@ -178,7 +180,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  
  @return Whether succeed.
  */
-- (BOOL)removeItemForKeys:(NSArray *)keys;
+- (BOOL)removeItemForKeys:(NSArray<NSString *> *)keys;
 
 /**
  Remove all items which `value` is larger than a specified size.
@@ -232,8 +234,8 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param progress This block will be invoked during removing, pass nil to ignore.
  @param end      This block will be invoked at the end, pass nil to ignore.
  */
-- (void)removeAllItemsWithProgressBlock:(void(^)(int removedCount, int totalCount))progress
-                               endBlock:(void(^)(BOOL error))end;
+- (void)removeAllItemsWithProgressBlock:(nullable void(^)(int removedCount, int totalCount))progress
+                               endBlock:(nullable void(^)(BOOL error))end;
 
 
 #pragma mark - Get Items
@@ -247,7 +249,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param key A specified key.
  @return Item for the key, or nil if not exists / error occurs.
  */
-- (YYKVStorageItem *)getItemForKey:(NSString *)key;
+- (nullable YYKVStorageItem *)getItemForKey:(NSString *)key;
 
 /**
  Get item information with a specified key.
@@ -256,7 +258,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param key A specified key.
  @return Item information for the key, or nil if not exists / error occurs.
  */
-- (YYKVStorageItem *)getItemInfoForKey:(NSString *)key;
+- (nullable YYKVStorageItem *)getItemInfoForKey:(NSString *)key;
 
 /**
  Get item value with a specified key.
@@ -264,7 +266,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param key  A specified key.
  @return Item's value, or nil if not exists / error occurs.
  */
-- (NSData *)getItemValueForKey:(NSString *)key;
+- (nullable NSData *)getItemValueForKey:(NSString *)key;
 
 /**
  Get items with an array of keys.
@@ -272,7 +274,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param keys  An array of specified keys.
  @return An array of `YYKVStorageItem`, or nil if not exists / error occurs.
  */
-- (NSArray *)getItemForKeys:(NSArray *)keys;
+- (nullable NSArray<YYKVStorageItem *> *)getItemForKeys:(NSArray<NSString *> *)keys;
 
 /**
  Get item infomartions with an array of keys.
@@ -281,7 +283,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @param keys  An array of specified keys.
  @return An array of `YYKVStorageItem`, or nil if not exists / error occurs.
  */
-- (NSArray *)getItemInfoForKeys:(NSArray *)keys;
+- (nullable NSArray<YYKVStorageItem *> *)getItemInfoForKeys:(NSArray<NSString *> *)keys;
 
 /**
  Get items value with an array of keys.
@@ -290,7 +292,7 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
  @return A dictionary which key is 'key' and value is 'value', or nil if not 
     exists / error occurs.
  */
-- (NSDictionary *)getItemValueForKeys:(NSArray *)keys;
+- (nullable NSDictionary<NSString *, NSData *> *)getItemValueForKeys:(NSArray<NSString *> *)keys;
 
 #pragma mark - Get Storage Status
 ///=============================================================================
@@ -319,3 +321,5 @@ typedef NS_ENUM(NSUInteger, YYKVStorageType) {
 - (int)getItemsSize;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 1 - 1
YYWebImage/Cache/YYKVStorage.m

@@ -649,7 +649,7 @@ static NSString *const kTrashDirectoryName = @"trash";
 
 - (instancetype)init {
     @throw [NSException exceptionWithName:@"YYKVStorage init error" reason:@"Please use the designated initializer and pass the 'path' and 'type'." userInfo:nil];
-    return [self initWithPath:nil type:YYKVStorageTypeFile];
+    return [self initWithPath:@"" type:YYKVStorageTypeFile];
 }
 
 - (instancetype)initWithPath:(NSString *)path type:(YYKVStorageType)type {

+ 18 - 14
YYWebImage/Cache/YYMemoryCache.h

@@ -11,6 +11,8 @@
 
 #import <Foundation/Foundation.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  YYMemoryCache is a fast in-memory cache that stores key-value pairs.
  In contrast to NSDictionary, keys are retained and not copied.
@@ -34,7 +36,7 @@
 ///=============================================================================
 
 /** The name of the cache. Default is nil. */
-@property (copy) NSString *name;
+@property (nullable, copy) NSString *name;
 
 /** The number of objects in the cache (read-only) */
 @property (readonly) NSUInteger totalCount;
@@ -55,7 +57,7 @@
  This is not a strict limit—if the cache goes over the limit, some objects in the
  cache could be evicted later in backgound thread.
  */
-@property (assign) NSUInteger countLimit;
+@property NSUInteger countLimit;
 
 /**
  The maximum total cost that the cache can hold before it starts evicting objects.
@@ -64,7 +66,7 @@
  This is not a strict limit—if the cache goes over the limit, some objects in the
  cache could be evicted later in backgound thread.
  */
-@property (assign) NSUInteger costLimit;
+@property NSUInteger costLimit;
 
 /**
  The maximum expiry time of objects in cache.
@@ -73,7 +75,7 @@
  This is not a strict limit—if an object goes over the limit, the object could 
  be evicted later in backgound thread.
  */
-@property (assign) NSTimeInterval ageLimit;
+@property NSTimeInterval ageLimit;
 
 /**
  The auto trim check time interval in seconds. Default is 5.0.
@@ -81,31 +83,31 @@
  @discussion The cache holds an internal timer to check whether the cache reaches 
  its limits, and if the limit is reached, it begins to evict objects.
  */
-@property (assign) NSTimeInterval autoTrimInterval;
+@property NSTimeInterval autoTrimInterval;
 
 /**
  If `YES`, the cache will remove all objects when the app receives a memory warning.
  The default value is `YES`.
  */
-@property (assign) BOOL shouldRemoveAllObjectsOnMemoryWarning;
+@property BOOL shouldRemoveAllObjectsOnMemoryWarning;
 
 /**
  If `YES`, The cache will remove all objects when the app enter background.
  The default value is `YES`.
  */
-@property (assign) BOOL shouldRemoveAllObjectsWhenEnteringBackground;
+@property BOOL shouldRemoveAllObjectsWhenEnteringBackground;
 
 /**
  A block to be executed when the app receives a memory warning.
  The default value is nil.
  */
-@property (copy) void(^didReceiveMemoryWarningBlock)(YYMemoryCache *cache);
+@property (nullable, copy) void(^didReceiveMemoryWarningBlock)(YYMemoryCache *cache);
 
 /**
  A block to be executed when the app enter background.
  The default value is nil.
  */
-@property (copy) void(^didEnterBackgroundBlock)(YYMemoryCache *cache);
+@property (nullable, copy) void(^didEnterBackgroundBlock)(YYMemoryCache *cache);
 
 /**
  If `YES`, the key-value pair will be released on main thread, otherwise on
@@ -114,14 +116,14 @@
  @discussion You may set this value to `YES` if the key-value object contains
  the instance which should be released in main thread (such as UIView/CALayer).
  */
-@property (assign) BOOL releaseOnMainThread;
+@property BOOL releaseOnMainThread;
 
 /**
  If `YES`, the key-value pair will be released asynchronously to avoid blocking 
  the access methods, otherwise it will be released in the access method  
  (such as removeObjectForKey:). Default is YES.
  */
-@property (assign) BOOL releaseAsynchronously;
+@property BOOL releaseAsynchronously;
 
 
 #pragma mark - Access Methods
@@ -143,7 +145,7 @@
  @param key An object identifying the value. If nil, just return nil.
  @return The value associated with key, or nil if no value is associated with key.
  */
-- (id)objectForKey:(id)key;
+- (nullable id)objectForKey:(id)key;
 
 /**
  Sets the value of the specified key in the cache (0 cost).
@@ -153,7 +155,7 @@
  @discussion Unlike an NSMutableDictionary object, a cache does not copy the key 
  objects that are put into it.
  */
-- (void)setObject:(id)object forKey:(id)key;
+- (void)setObject:(nullable id)object forKey:(id)key;
 
 /**
  Sets the value of the specified key in the cache, and associates the key-value 
@@ -165,7 +167,7 @@
  @discussion Unlike an NSMutableDictionary object, a cache does not copy the key
  objects that are put into it.
  */
-- (void)setObject:(id)object forKey:(id)key withCost:(NSUInteger)cost;
+- (void)setObject:(nullable id)object forKey:(id)key withCost:(NSUInteger)cost;
 
 /**
  Removes the value of the specified key in the cache.
@@ -207,3 +209,5 @@
 - (void)trimToAge:(NSTimeInterval)age;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 20 - 18
YYWebImage/Categories/CALayer+YYWebImage.h

@@ -18,6 +18,7 @@
 #import "YYWebImageManager.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 /**
  Web image methods for CALayer.
@@ -25,7 +26,6 @@
  */
 @interface CALayer (YYWebImage)
 
-
 #pragma mark - image
 
 /**
@@ -35,7 +35,7 @@
  operation and create a new request operation to fetch image. Set nil to clear
  the image and image URL.
  */
-@property (nonatomic, strong) NSURL *yy_imageURL;
+@property (nullable, nonatomic, strong) NSURL *yy_imageURL;
 
 /**
  Set the view's `image` with a specified URL.
@@ -43,7 +43,7 @@
  @param imageURL    The image url (remote or local file path).
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the view's `image` with a specified URL.
@@ -51,7 +51,7 @@
  @param imageURL The image url (remote or local file path).
  @param options  The options to use when request the image.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL options:(YYWebImageOptions)options;
 
 /**
  Set the view's `image` with a specified URL.
@@ -61,10 +61,10 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                completion:(YYWebImageCompletionBlock)completion;
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -76,12 +76,12 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -94,13 +94,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                   manager:(YYWebImageManager *)manager
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                   manager:(nullable YYWebImageManager *)manager
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current image request.
@@ -108,3 +108,5 @@
 - (void)yy_cancelCurrentImageRequest;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 20 - 17
YYWebImage/Categories/MKAnnotationView+YYWebImage.h

@@ -18,6 +18,7 @@
 #import "YYWebImageManager.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 /**
  Web image methods for MKAnnotationView.
@@ -31,7 +32,7 @@
  operation and create a new request operation to fetch image. Set nil to clear
  the image and image URL.
  */
-@property (nonatomic, strong) NSURL *yy_imageURL;
+@property (nullable, nonatomic, strong) NSURL *yy_imageURL;
 
 /**
  Set the view's `image` with a specified URL.
@@ -39,7 +40,7 @@
  @param imageURL    The image url (remote or local file path).
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the view's `image` with a specified URL.
@@ -47,7 +48,7 @@
  @param imageURL The image url (remote or local file path).
  @param options  The options to use when request the image.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL options:(YYWebImageOptions)options;
 
 /**
  Set the view's `image` with a specified URL.
@@ -57,10 +58,10 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                completion:(YYWebImageCompletionBlock)completion;
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -72,12 +73,12 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -90,13 +91,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                   manager:(YYWebImageManager *)manager
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                   manager:(nullable YYWebImageManager *)manager
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current image request.
@@ -104,3 +105,5 @@
 - (void)yy_cancelCurrentImageRequest;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 39 - 36
YYWebImage/Categories/UIButton+YYWebImage.h

@@ -17,6 +17,7 @@
 #import "YYWebImageManager.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 /**
  Web image methods for UIButton.
@@ -29,7 +30,7 @@
  Current image URL for the specified state.
  @return The image URL, or nil.
  */
-- (NSURL *)yy_imageURLForState:(UIControlState)state;
+- (nullable NSURL *)yy_imageURLForState:(UIControlState)state;
 
 /**
  Set the button's image with a specified URL for the specified state.
@@ -38,9 +39,9 @@
  @param state       The state that uses the specified image.
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
                   forState:(UIControlState)state
-               placeholder:(UIImage *)placeholder;
+               placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the button's image with a specified URL for the specified state.
@@ -49,7 +50,7 @@
  @param state    The state that uses the specified image.
  @param options  The options to use when request the image.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
                   forState:(UIControlState)state
                    options:(YYWebImageOptions)options;
 
@@ -62,11 +63,11 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
                   forState:(UIControlState)state
-               placeholder:(UIImage *)placeholder
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                completion:(YYWebImageCompletionBlock)completion;
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the button's image with a specified URL for the specified state.
@@ -79,13 +80,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
                   forState:(UIControlState)state
-               placeholder:(UIImage *)placeholder
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the button's image with a specified URL for the specified state.
@@ -99,14 +100,14 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
                   forState:(UIControlState)state
-               placeholder:(UIImage *)placeholder
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                   manager:(YYWebImageManager *)manager
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                   manager:(nullable YYWebImageManager *)manager
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current image request for a specified state.
@@ -122,7 +123,7 @@
  Current backgroundImage URL for the specified state.
  @return The image URL, or nil.
  */
-- (NSURL *)yy_backgroundImageURLForState:(UIControlState)state;
+- (nullable NSURL *)yy_backgroundImageURLForState:(UIControlState)state;
 
 /**
  Set the button's backgroundImage with a specified URL for the specified state.
@@ -131,9 +132,9 @@
  @param state       The state that uses the specified image.
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
+- (void)yy_setBackgroundImageWithURL:(nullable NSURL *)imageURL
                             forState:(UIControlState)state
-                         placeholder:(UIImage *)placeholder;
+                         placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the button's backgroundImage with a specified URL for the specified state.
@@ -142,7 +143,7 @@
  @param state    The state that uses the specified image.
  @param options  The options to use when request the image.
  */
-- (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
+- (void)yy_setBackgroundImageWithURL:(nullable NSURL *)imageURL
                             forState:(UIControlState)state
                              options:(YYWebImageOptions)options;
 
@@ -155,11 +156,11 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
+- (void)yy_setBackgroundImageWithURL:(nullable NSURL *)imageURL
                             forState:(UIControlState)state
-                         placeholder:(UIImage *)placeholder
+                         placeholder:(nullable UIImage *)placeholder
                              options:(YYWebImageOptions)options
-                          completion:(YYWebImageCompletionBlock)completion;
+                          completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the button's backgroundImage with a specified URL for the specified state.
@@ -172,13 +173,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
+- (void)yy_setBackgroundImageWithURL:(nullable NSURL *)imageURL
                             forState:(UIControlState)state
-                         placeholder:(UIImage *)placeholder
+                         placeholder:(nullable UIImage *)placeholder
                              options:(YYWebImageOptions)options
-                            progress:(YYWebImageProgressBlock)progress
-                           transform:(YYWebImageTransformBlock)transform
-                          completion:(YYWebImageCompletionBlock)completion;
+                            progress:(nullable YYWebImageProgressBlock)progress
+                           transform:(nullable YYWebImageTransformBlock)transform
+                          completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the button's backgroundImage with a specified URL for the specified state.
@@ -192,14 +193,14 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
+- (void)yy_setBackgroundImageWithURL:(nullable NSURL *)imageURL
                             forState:(UIControlState)state
-                         placeholder:(UIImage *)placeholder
+                         placeholder:(nullable UIImage *)placeholder
                              options:(YYWebImageOptions)options
-                             manager:(YYWebImageManager *)manager
-                            progress:(YYWebImageProgressBlock)progress
-                           transform:(YYWebImageTransformBlock)transform
-                          completion:(YYWebImageCompletionBlock)completion;
+                             manager:(nullable YYWebImageManager *)manager
+                            progress:(nullable YYWebImageProgressBlock)progress
+                           transform:(nullable YYWebImageTransformBlock)transform
+                          completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current backgroundImage request for a specified state.
@@ -208,3 +209,5 @@
 - (void)yy_cancelBackgroundImageRequestForState:(UIControlState)state;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 38 - 34
YYWebImage/Categories/UIImage+YYWebImage.h

@@ -11,6 +11,8 @@
 
 #import <UIKit/UIKit.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  Provide some commen method for `UIImage`.
  Image process is based on CoreGraphic and vImage.
@@ -38,14 +40,14 @@
  
  @return A new image created from GIF, or nil when an error occurs.
  */
-+ (UIImage *)yy_imageWithSmallGIFData:(NSData *)data scale:(CGFloat)scale;
++ (nullable UIImage *)yy_imageWithSmallGIFData:(NSData *)data scale:(CGFloat)scale;
 
 /**
  Create and return a 1x1 point size image with the given color.
  
  @param color  The color.
  */
-+ (UIImage *)yy_imageWithColor:(UIColor *)color;
++ (nullable UIImage *)yy_imageWithColor:(UIColor *)color;
 
 /**
  Create and return a pure color image with the given color and size.
@@ -53,7 +55,7 @@
  @param color  The color.
  @param size   New image's type.
  */
-+ (UIImage *)yy_imageWithColor:(UIColor *)color size:(CGSize)size;
++ (nullable UIImage *)yy_imageWithColor:(UIColor *)color size:(CGSize)size;
 
 /**
  Create and return an image with custom draw code.
@@ -63,7 +65,7 @@
  
  @return The new image.
  */
-+ (UIImage *)yy_imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock;
++ (nullable UIImage *)yy_imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock;
 
 #pragma mark - Image Info
 ///=============================================================================
@@ -107,7 +109,7 @@
  
  @return      The new image with the given size.
  */
-- (UIImage *)yy_imageByResizeToSize:(CGSize)size;
+- (nullable UIImage *)yy_imageByResizeToSize:(CGSize)size;
 
 /**
  Returns a new image which is scaled from this image.
@@ -119,7 +121,7 @@
  
  @return The new image with the given size.
  */
-- (UIImage *)yy_imageByResizeToSize:(CGSize)size contentMode:(UIViewContentMode)contentMode;
+- (nullable UIImage *)yy_imageByResizeToSize:(CGSize)size contentMode:(UIViewContentMode)contentMode;
 
 /**
  Returns a new image which is cropped from this image.
@@ -128,7 +130,7 @@
  
  @return      The new image, or nil if an error occurs.
  */
-- (UIImage *)yy_imageByCropToRect:(CGRect)rect;
+- (nullable UIImage *)yy_imageByCropToRect:(CGRect)rect;
 
 /**
  Returns a new image which is edge inset from this image.
@@ -139,7 +141,7 @@
  
  @return        The new image, or nil if an error occurs.
  */
-- (UIImage *)yy_imageByInsetEdge:(UIEdgeInsets)insets withColor:(UIColor *)color;
+- (nullable UIImage *)yy_imageByInsetEdge:(UIEdgeInsets)insets withColor:(nullable UIColor *)color;
 
 /**
  Rounds a new image with a given corner size.
@@ -148,7 +150,7 @@
                 rectangle's width or height are clamped appropriately to half
                 the width or height.
  */
-- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius;
+- (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius;
 
 /**
  Rounds a new image with a given corner size.
@@ -163,9 +165,9 @@
  
  @param borderColor  The border stroke color. nil means clear color.
  */
-- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
+- (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
                              borderWidth:(CGFloat)borderWidth
-                             borderColor:(UIColor *)borderColor;
+                             borderColor:(nullable UIColor *)borderColor;
 
 /**
  Rounds a new image with a given corner size.
@@ -186,11 +188,11 @@
  
  @param borderLineJoin The border line join.
  */
-- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
-                                 corners:(UIRectCorner)corners
-                             borderWidth:(CGFloat)borderWidth
-                             borderColor:(UIColor *)borderColor
-                          borderLineJoin:(CGLineJoin)borderLineJoin;
+- (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
+                                          corners:(UIRectCorner)corners
+                                      borderWidth:(CGFloat)borderWidth
+                                      borderColor:(nullable UIColor *)borderColor
+                                   borderLineJoin:(CGLineJoin)borderLineJoin;
 
 /**
  Returns a new rotated image (relative to the center).
@@ -200,34 +202,34 @@
  @param fitSize   YES: new image's size is extend to fit all content.
                   NO: image's size will not change, content may be clipped.
  */
-- (UIImage *)yy_imageByRotate:(CGFloat)radians fitSize:(BOOL)fitSize;
+- (nullable UIImage *)yy_imageByRotate:(CGFloat)radians fitSize:(BOOL)fitSize;
 
 /**
  Returns a new image rotated counterclockwise by a quarter‑turn (90°). ⤺
  The width and height will be exchanged.
  */
-- (UIImage *)yy_imageByRotateLeft90;
+- (nullable UIImage *)yy_imageByRotateLeft90;
 
 /**
  Returns a new image rotated clockwise by a quarter‑turn (90°). ⤼
  The width and height will be exchanged.
  */
-- (UIImage *)yy_imageByRotateRight90;
+- (nullable UIImage *)yy_imageByRotateRight90;
 
 /**
  Returns a new image rotated 180° . ↻
  */
-- (UIImage *)yy_imageByRotate180;
+- (nullable UIImage *)yy_imageByRotate180;
 
 /**
  Returns a vertically flipped image. ⥯
  */
-- (UIImage *)yy_imageByFlipVertical;
+- (nullable UIImage *)yy_imageByFlipVertical;
 
 /**
  Returns a horizontally flipped image. ⇋
  */
-- (UIImage *)yy_imageByFlipHorizontal;
+- (nullable UIImage *)yy_imageByFlipHorizontal;
 
 
 #pragma mark - Image Effect
@@ -240,42 +242,42 @@
  
  @param color  The color.
  */
-- (UIImage *)yy_imageByTintColor:(UIColor *)color;
+- (nullable UIImage *)yy_imageByTintColor:(UIColor *)color;
 
 /**
  Returns a grayscaled image.
  */
-- (UIImage *)yy_imageByGrayscale;
+- (nullable UIImage *)yy_imageByGrayscale;
 
 /**
  Applies a blur effect to this image. Suitable for blur any content.
  */
-- (UIImage *)yy_imageByBlurSoft;
+- (nullable UIImage *)yy_imageByBlurSoft;
 
 /**
  Applies a blur effect to this image. Suitable for blur any content except pure white.
  (same as iOS Control Panel)
  */
-- (UIImage *)yy_imageByBlurLight;
+- (nullable UIImage *)yy_imageByBlurLight;
 
 /**
  Applies a blur effect to this image. Suitable for displaying black text.
  (same as iOS Navigation Bar White)
  */
-- (UIImage *)yy_imageByBlurExtraLight;
+- (nullable UIImage *)yy_imageByBlurExtraLight;
 
 /**
  Applies a blur effect to this image. Suitable for displaying white text.
  (same as iOS Notification Center)
  */
-- (UIImage *)yy_imageByBlurDark;
+- (nullable UIImage *)yy_imageByBlurDark;
 
 /**
  Applies a blur and tint color to this image.
  
  @param tintColor  The tint color.
  */
-- (UIImage *)yy_imageByBlurWithTint:(UIColor *)tintColor;
+- (nullable UIImage *)yy_imageByBlurWithTint:(UIColor *)tintColor;
 
 /**
  Applies a blur, tint color, and saturation adjustment to this image,
@@ -303,10 +305,12 @@
  @return               image with effect, or nil if an error occurs (e.g. no
                        enough memory).
  */
-- (UIImage *)yy_imageByBlurRadius:(CGFloat)blurRadius
-                        tintColor:(UIColor *)tintColor
-                         tintMode:(CGBlendMode)tintBlendMode
-                       saturation:(CGFloat)saturation
-                        maskImage:(UIImage *)maskImage;
+- (nullable UIImage *)yy_imageByBlurRadius:(CGFloat)blurRadius
+                                 tintColor:(nullable UIColor *)tintColor
+                                  tintMode:(CGBlendMode)tintBlendMode
+                                saturation:(CGFloat)saturation
+                                 maskImage:(nullable UIImage *)maskImage;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 37 - 34
YYWebImage/Categories/UIImageView+YYWebImage.h

@@ -17,6 +17,7 @@
 #import "YYWebImageManager.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 /**
  Web image methods for UIImageView.
@@ -32,7 +33,7 @@
  operation and create a new request operation to fetch image. Set nil to clear 
  the image and image URL.
  */
-@property (nonatomic, strong) NSURL *yy_imageURL;
+@property (nullable, nonatomic, strong) NSURL *yy_imageURL;
 
 /**
  Set the view's `image` with a specified URL.
@@ -40,7 +41,7 @@
  @param imageURL    The image url (remote or local file path).
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the view's `image` with a specified URL.
@@ -48,7 +49,7 @@
  @param imageURL The image url (remote or local file path).
  @param options  The options to use when request the image.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options;
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL options:(YYWebImageOptions)options;
 
 /**
  Set the view's `image` with a specified URL.
@@ -58,10 +59,10 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                completion:(YYWebImageCompletionBlock)completion;
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -73,12 +74,12 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `image` with a specified URL.
@@ -91,13 +92,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setImageWithURL:(NSURL *)imageURL
-               placeholder:(UIImage *)placeholder
+- (void)yy_setImageWithURL:(nullable NSURL *)imageURL
+               placeholder:(nullable UIImage *)placeholder
                    options:(YYWebImageOptions)options
-                   manager:(YYWebImageManager *)manager
-                  progress:(YYWebImageProgressBlock)progress
-                 transform:(YYWebImageTransformBlock)transform
-                completion:(YYWebImageCompletionBlock)completion;
+                   manager:(nullable YYWebImageManager *)manager
+                  progress:(nullable YYWebImageProgressBlock)progress
+                 transform:(nullable YYWebImageTransformBlock)transform
+                completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current image request.
@@ -115,7 +116,7 @@
  operation and create a new request operation to fetch image. Set nil to clear
  the highlighted image and image URL.
  */
-@property (nonatomic, strong) NSURL *yy_highlightedImageURL;
+@property (nullable, nonatomic, strong) NSURL *yy_highlightedImageURL;
 
 /**
  Set the view's `highlightedImage` with a specified URL.
@@ -123,7 +124,7 @@
  @param imageURL    The image url (remote or local file path).
  @param placeholder The image to be set initially, until the image request finishes.
  */
-- (void)yy_setHighlightedImageWithURL:(NSURL *)imageURL placeholder:(UIImage *)placeholder;
+- (void)yy_setHighlightedImageWithURL:(nullable NSURL *)imageURL placeholder:(nullable UIImage *)placeholder;
 
 /**
  Set the view's `highlightedImage` with a specified URL.
@@ -131,7 +132,7 @@
  @param imageURL The image url (remote or local file path).
  @param options  The options to use when request the image.
  */
-- (void)yy_setHighlightedImageWithURL:(NSURL *)imageURL options:(YYWebImageOptions)options;
+- (void)yy_setHighlightedImageWithURL:(nullable NSURL *)imageURL options:(YYWebImageOptions)options;
 
 /**
  Set the view's `highlightedImage` with a specified URL.
@@ -141,10 +142,10 @@
  @param options     The options to use when request the image.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setHighlightedImageWithURL:(NSURL *)imageURL
-                          placeholder:(UIImage *)placeholder
+- (void)yy_setHighlightedImageWithURL:(nullable NSURL *)imageURL
+                          placeholder:(nullable UIImage *)placeholder
                               options:(YYWebImageOptions)options
-                           completion:(YYWebImageCompletionBlock)completion;
+                           completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `highlightedImage` with a specified URL.
@@ -156,12 +157,12 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setHighlightedImageWithURL:(NSURL *)imageURL
-                          placeholder:(UIImage *)placeholder
+- (void)yy_setHighlightedImageWithURL:(nullable NSURL *)imageURL
+                          placeholder:(nullable UIImage *)placeholder
                               options:(YYWebImageOptions)options
-                             progress:(YYWebImageProgressBlock)progress
-                            transform:(YYWebImageTransformBlock)transform
-                           completion:(YYWebImageCompletionBlock)completion;
+                             progress:(nullable YYWebImageProgressBlock)progress
+                            transform:(nullable YYWebImageTransformBlock)transform
+                           completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Set the view's `highlightedImage` with a specified URL.
@@ -174,13 +175,13 @@
  @param transform   The block invoked (on background thread) to do additional image process.
  @param completion  The block invoked (on main thread) when image request completed.
  */
-- (void)yy_setHighlightedImageWithURL:(NSURL *)imageURL
-                          placeholder:(UIImage *)placeholder
+- (void)yy_setHighlightedImageWithURL:(nullable NSURL *)imageURL
+                          placeholder:(nullable UIImage *)placeholder
                               options:(YYWebImageOptions)options
-                              manager:(YYWebImageManager *)manager
-                             progress:(YYWebImageProgressBlock)progress
-                            transform:(YYWebImageTransformBlock)transform
-                           completion:(YYWebImageCompletionBlock)completion;
+                              manager:(nullable YYWebImageManager *)manager
+                             progress:(nullable YYWebImageProgressBlock)progress
+                            transform:(nullable YYWebImageTransformBlock)transform
+                           completion:(nullable YYWebImageCompletionBlock)completion;
 
 /**
  Cancel the current highlighed image request.
@@ -188,3 +189,5 @@
 - (void)yy_cancelCurrentHighlightedImageRequest;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 9 - 6
YYWebImage/Categories/_YYWebImageSetter.h

@@ -17,6 +17,7 @@
 #import "YYWebImageManager.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
 
 /**
  Submits a block for execution on a main queue and waits until the block completes.
@@ -39,24 +40,26 @@ extern const NSTimeInterval _YYWebImageProgressiveFadeTime;
  */
 @interface _YYWebImageSetter : NSObject
 /// Current image url.
-@property (nonatomic, readonly) NSURL *imageURL;
+@property (nullable, nonatomic, readonly) NSURL *imageURL;
 
 /// Create new operation for web image.
 - (void)setOperationWithSentinel:(int32_t)sentinel
-                             url:(NSURL *)imageURL
+                             url:(nullable NSURL *)imageURL
                          options:(YYWebImageOptions)options
                          manager:(YYWebImageManager *)manager
-                        progress:(YYWebImageProgressBlock)progress
-                       transform:(YYWebImageTransformBlock)transform
-                      completion:(YYWebImageCompletionBlock)completion;
+                        progress:(nullable YYWebImageProgressBlock)progress
+                       transform:(nullable YYWebImageTransformBlock)transform
+                      completion:(nullable YYWebImageCompletionBlock)completion;
 
 /// Cancel and return a sentinel value. The imageURL will be set to nil.
 - (int32_t)cancel;
 
 /// Cancel and return a sentinel value. The imageURL will be set to new value.
-- (int32_t)cancelWithNewURL:(NSURL *)imageURL;
+- (int32_t)cancelWithNewURL:(nullable NSURL *)imageURL;
 
 /// A queue to set operation.
 + (dispatch_queue_t)setterQueue;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 8 - 4
YYWebImage/Image/YYAnimatedImageView.h

@@ -11,6 +11,8 @@
 
 #import <UIKit/UIKit.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  An image view for displaying animated image.
  
@@ -38,7 +40,7 @@
  
  The default value is `YES`.
  */
-@property (nonatomic, assign) BOOL autoPlayAnimatedImage;
+@property (nonatomic) BOOL autoPlayAnimatedImage;
 
 /**
  Index of the currently displayed frame (index from 0).
@@ -48,7 +50,7 @@
  
  You can add an observer to this property to observe the playing status.
  */
-@property (nonatomic, assign) NSUInteger currentAnimatedImageIndex;
+@property (nonatomic) NSUInteger currentAnimatedImageIndex;
 
 /**
  Whether the image view is playing animation currently.
@@ -76,7 +78,7 @@
  When receive memory warning or app enter background, the buffer will be released 
  immediately, and may grow back at the right time.
  */
-@property (nonatomic, assign) NSUInteger maxBufferSize;
+@property (nonatomic) NSUInteger maxBufferSize;
 
 @end
 
@@ -107,7 +109,7 @@
 /// Returns the frame image from a specified index.
 /// This method may be called on background thread.
 /// @param index  Frame index (zero based).
-- (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index;
+- (nullable UIImage *)animatedImageFrameAtIndex:(NSUInteger)index;
 
 /// Returns the frames's duration from a specified index.
 /// @param index  Frame index (zero based).
@@ -119,3 +121,5 @@
 /// It may used to display sprite animation with a single image (sprite sheet).
 - (CGRect)animatedImageContentsRectAtIndex:(NSUInteger)index;
 @end
+
+NS_ASSUME_NONNULL_END

+ 16 - 4
YYWebImage/Image/YYFrameImage.h

@@ -19,6 +19,8 @@
 #import "YYAnimatedImageView.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  An image to display frame-based animation.
  
@@ -49,7 +51,9 @@
  
  @return An initialized YYFrameImage object, or nil when an error occurs.
  */
-- (instancetype)initWithImagePaths:(NSArray *)paths oneFrameDuration:(NSTimeInterval)oneFrameDuration loopCount:(NSUInteger)loopCount;
+- (nullable instancetype)initWithImagePaths:(NSArray<NSString *> *)paths
+                           oneFrameDuration:(NSTimeInterval)oneFrameDuration
+                                  loopCount:(NSUInteger)loopCount;
 
 /**
  Create a frame animated image from files.
@@ -65,7 +69,9 @@
  
  @return An initialized YYFrameImage object, or nil when an error occurs.
  */
-- (instancetype)initWithImagePaths:(NSArray *)paths frameDurations:(NSArray *)frameDurations loopCount:(NSUInteger)loopCount;
+- (nullable instancetype)initWithImagePaths:(NSArray<NSString *> *)paths
+                             frameDurations:(NSArray<NSNumber *> *)frameDurations
+                                  loopCount:(NSUInteger)loopCount;
 
 /**
  Create a frame animated image from an array of data.
@@ -78,7 +84,9 @@
  
  @return An initialized YYFrameImage object, or nil when an error occurs.
  */
-- (instancetype)initWithImageDataArray:(NSArray *)dataArray oneFrameDuration:(NSTimeInterval)oneFrameDuration loopCount:(NSUInteger)loopCount;
+- (nullable instancetype)initWithImageDataArray:(NSArray<NSData *> *)dataArray
+                               oneFrameDuration:(NSTimeInterval)oneFrameDuration
+                                      loopCount:(NSUInteger)loopCount;
 
 /**
  Create a frame animated image from an array of data.
@@ -92,6 +100,10 @@
  
  @return An initialized YYFrameImage object, or nil when an error occurs.
  */
-- (instancetype)initWithImageDataArray:(NSArray *)dataArray frameDurations:(NSArray *)frameDurations loopCount:(NSUInteger)loopCount;
+- (nullable instancetype)initWithImageDataArray:(NSArray<NSData *> *)dataArray
+                                 frameDurations:(NSArray *)frameDurations
+                                      loopCount:(NSUInteger)loopCount;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 9 - 7
YYWebImage/Image/YYImage.h

@@ -30,7 +30,7 @@ FOUNDATION_EXPORT const unsigned char YYImageVersionString[];
 #import "YYAnimatedImageView.h"
 #endif
 
-
+NS_ASSUME_NONNULL_BEGIN
 
 
 /**
@@ -53,10 +53,10 @@ FOUNDATION_EXPORT const unsigned char YYImageVersionString[];
  */
 @interface YYImage : UIImage <YYAnimatedImage>
 
-+ (YYImage *)imageNamed:(NSString *)name; // no cache!
-+ (YYImage *)imageWithContentsOfFile:(NSString *)path;
-+ (YYImage *)imageWithData:(NSData *)data;
-+ (YYImage *)imageWithData:(NSData *)data scale:(CGFloat)scale;
++ (nullable YYImage *)imageNamed:(NSString *)name; // no cache!
++ (nullable YYImage *)imageWithContentsOfFile:(NSString *)path;
++ (nullable YYImage *)imageWithData:(NSData *)data;
++ (nullable YYImage *)imageWithData:(NSData *)data scale:(CGFloat)scale;
 
 /**
  If the image is created from data or file, then the value indicates the data type.
@@ -67,7 +67,7 @@ FOUNDATION_EXPORT const unsigned char YYImageVersionString[];
  If the image is created from animated image data (multi-frame GIF/APNG/WebP),
  this property stores the original image data.
  */
-@property (nonatomic, readonly) NSData *animatedImageData;
+@property (nullable, nonatomic, readonly) NSData *animatedImageData;
 
 /**
  The total memory usage (in bytes) if all frame images was loaded into memory.
@@ -85,6 +85,8 @@ FOUNDATION_EXPORT const unsigned char YYImageVersionString[];
  
  See `animatedImageMemorySize` for memory cost.
  */
-@property (nonatomic, assign) BOOL preloadAllAnimatedImageFrames;
+@property (nonatomic) BOOL preloadAllAnimatedImageFrames;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 53 - 50
YYWebImage/Image/YYImageCoder.h

@@ -11,6 +11,8 @@
 
 #import <UIKit/UIKit.h>
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  Image file type.
  */
@@ -76,15 +78,15 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  An image frame object.
  */
 @interface YYImageFrame : NSObject <NSCopying>
-@property (nonatomic, assign) NSUInteger index;    ///< Frame index (zero based)
-@property (nonatomic, assign) NSUInteger width;    ///< Frame width
-@property (nonatomic, assign) NSUInteger height;   ///< Frame height
-@property (nonatomic, assign) NSUInteger offsetX;  ///< Frame origin.x in canvas (left-bottom based)
-@property (nonatomic, assign) NSUInteger offsetY;  ///< Frame origin.y in canvas (left-bottom based)
-@property (nonatomic, assign) NSTimeInterval duration;      ///< Frame duration in seconds
-@property (nonatomic, assign) YYImageDisposeMethod dispose; ///< Frame dispose method.
-@property (nonatomic, assign) YYImageBlendOperation blend;  ///< Frame blend operation.
-@property (nonatomic, strong) UIImage *image; ///< The image.
+@property (nonatomic) NSUInteger index;    ///< Frame index (zero based)
+@property (nonatomic) NSUInteger width;    ///< Frame width
+@property (nonatomic) NSUInteger height;   ///< Frame height
+@property (nonatomic) NSUInteger offsetX;  ///< Frame origin.x in canvas (left-bottom based)
+@property (nonatomic) NSUInteger offsetY;  ///< Frame origin.y in canvas (left-bottom based)
+@property (nonatomic) NSTimeInterval duration;          ///< Frame duration in seconds
+@property (nonatomic) YYImageDisposeMethod dispose;     ///< Frame dispose method.
+@property (nonatomic) YYImageBlendOperation blend;      ///< Frame blend operation.
+@property (nullable, nonatomic, strong) UIImage *image; ///< The image.
 + (instancetype)frameWithImage:(UIImage *)image;
 @end
 
@@ -124,9 +126,9 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  */
 @interface YYImageDecoder : NSObject
 
-@property (nonatomic, readonly) NSData *data;       ///< Image data.
-@property (nonatomic, readonly) YYImageType type;   ///< Image data type.
-@property (nonatomic, readonly) CGFloat scale;      ///< Image scale.
+@property (nullable, nonatomic, readonly) NSData *data;    ///< Image data.
+@property (nonatomic, readonly) YYImageType type;          ///< Image data type.
+@property (nonatomic, readonly) CGFloat scale;             ///< Image scale.
 @property (nonatomic, readonly) NSUInteger frameCount;     ///< Image frame count.
 @property (nonatomic, readonly) NSUInteger loopCount;      ///< Image loop count, 0 means infinite.
 @property (nonatomic, readonly) NSUInteger width;          ///< Image canvas width.
@@ -158,7 +160,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  
  @return Whether succeed.
  */
-- (BOOL)updateData:(NSData *)data final:(BOOL)final;
+- (BOOL)updateData:(nullable NSData *)data final:(BOOL)final;
 
 /**
  Convenience method to create a decoder with specified data.
@@ -166,7 +168,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  @param scale Image's scale.
  @return A new decoder, or nil if an error occurs.
  */
-+ (instancetype)decoderWithData:(NSData *)data scale:(CGFloat)scale;
++ (nullable instancetype)decoderWithData:(NSData *)data scale:(CGFloat)scale;
 
 /**
  Decodes and returns a frame from a specified index.
@@ -175,7 +177,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
     If NO, it will try to returns the original frame data without blend.
  @return A new frame with image, or nil if an error occurs.
  */
-- (YYImageFrame *)frameAtIndex:(NSUInteger)index decodeForDisplay:(BOOL)decodeForDisplay;
+- (nullable YYImageFrame *)frameAtIndex:(NSUInteger)index decodeForDisplay:(BOOL)decodeForDisplay;
 
 /**
  Returns the frame duration from a specified index.
@@ -191,13 +193,13 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  @param index  Frame image index (zero-based).
  @return The ImageIO frame property.
  */
-- (NSDictionary *)framePropertiesAtIndex:(NSUInteger)index;
+- (nullable NSDictionary *)framePropertiesAtIndex:(NSUInteger)index;
 
 /**
  Returns the image's properties. See "CGImageProperties.h" in ImageIO.framework
  for more information.
  */
-- (NSDictionary *)imageProperties;
+- (nullable NSDictionary *)imageProperties;
 
 @end
 
@@ -231,10 +233,10 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  */
 @interface YYImageEncoder : NSObject
 
-@property (nonatomic, readonly) YYImageType type;   ///< Image type.
-@property (nonatomic, assign) NSUInteger loopCount; ///< Loop count, 0 means infinit, only available for GIF/APNG/WebP.
-@property (nonatomic, assign) BOOL lossless;        ///< Lossless, only available for WebP.
-@property (nonatomic, assign) CGFloat quality;      ///< Compress quality, 0.0~1.0, only available for JPG/JP2/WebP.
+@property (nonatomic, readonly) YYImageType type; ///< Image type.
+@property (nonatomic) NSUInteger loopCount;       ///< Loop count, 0 means infinit, only available for GIF/APNG/WebP.
+@property (nonatomic) BOOL lossless;              ///< Lossless, only available for WebP.
+@property (nonatomic) CGFloat quality;            ///< Compress quality, 0.0~1.0, only available for JPG/JP2/WebP.
 
 - (instancetype)init UNAVAILABLE_ATTRIBUTE;
 + (instancetype)new UNAVAILABLE_ATTRIBUTE;
@@ -244,7 +246,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  @param type Image type.
  @return A new encoder, or nil if an error occurs.
  */
-- (instancetype)initWithType:(YYImageType)type NS_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithType:(YYImageType)type NS_DESIGNATED_INITIALIZER;
 
 /**
  Add an image to encoder.
@@ -271,7 +273,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  Encodes the image and returns the image data.
  @return The image data, or nil if an error occurs.
  */
-- (NSData *)encode;
+- (nullable NSData *)encode;
 
 /**
  Encodes the image to a file.
@@ -287,7 +289,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  @param quality Image quality, 0.0~1.0.
  @return The image data, or nil if an error occurs.
  */
-+ (NSData *)encodeImage:(UIImage *)image type:(YYImageType)type quality:(CGFloat)quality;
++ (nullable NSData *)encodeImage:(UIImage *)image type:(YYImageType)type quality:(CGFloat)quality;
 
 /**
  Convenience method to encode image from a decoder.
@@ -296,7 +298,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  @param quality Image quality, 0.0~1.0.
  @return The image data, or nil if an error occurs.
  */
-+ (NSData *)encodeImageWithDecoder:(YYImageDecoder *)decoder type:(YYImageType)type quality:(CGFloat)quality;
++ (nullable NSData *)encodeImageWithDecoder:(YYImageDecoder *)decoder type:(YYImageType)type quality:(CGFloat)quality;
 
 @end
 
@@ -319,7 +321,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  Wherher the image can be display on screen without additional decoding.
  @warning It just a hint for your code, change it has no other effect.
  */
-@property (nonatomic, assign) BOOL yy_isDecodedForDisplay;
+@property (nonatomic) BOOL yy_isDecodedForDisplay;
 
 /**
  Saves this image to iOS Photos Album. 
@@ -332,7 +334,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
     assetURL: An URL that identifies the saved image file. If the image is not saved, assetURL is nil.
     error: If the image is not saved, an error object that describes the reason for failure, otherwise nil.
  */
-- (void)yy_saveToAlbumWithCompletionBlock:(void(^)(NSURL *assetURL, NSError *error))completionBlock;
+- (void)yy_saveToAlbumWithCompletionBlock:(nullable void(^)(NSURL * _Nullable assetURL, NSError * _Nullable error))completionBlock;
 
 /**
  Return a 'best' data representation for this image.
@@ -343,7 +345,7 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
  
  @return Image data, or nil if an error occurs.
  */
-- (NSData *)yy_imageDataRepresentation;
+- (nullable NSData *)yy_imageDataRepresentation;
 
 @end
 
@@ -355,13 +357,13 @@ typedef NS_ENUM(NSUInteger, YYImageBlendOperation) {
 CG_EXTERN YYImageType YYImageDetectType(CFDataRef data);
 
 /// Convert YYImageType to UTI (such as kUTTypeJPEG).
-CG_EXTERN CFStringRef YYImageTypeToUTType(YYImageType type);
+CG_EXTERN CFStringRef _Nullable YYImageTypeToUTType(YYImageType type);
 
 /// Convert UTI (such as kUTTypeJPEG) to YYImageType.
 CG_EXTERN YYImageType YYImageTypeFromUTType(CFStringRef uti);
 
 /// Get image type's file extension (such as @"jpg").
-CG_EXTERN NSString *YYImageTypeGetExtension(YYImageType type);
+CG_EXTERN NSString *_Nullable YYImageTypeGetExtension(YYImageType type);
 
 
 
@@ -402,7 +404,7 @@ CG_EXTERN NSInteger YYUIImageOrientationToEXIFValue(UIImageOrientation orientati
  
  @return A decoded image, or NULL if an error occurs.
  */
-CG_EXTERN CGImageRef YYCGImageCreateDecodedCopy(CGImageRef imageRef, BOOL decodeForDisplay);
+CG_EXTERN CGImageRef _Nullable YYCGImageCreateDecodedCopy(CGImageRef imageRef, BOOL decodeForDisplay);
 
 /**
  Create an image copy with an orientation.
@@ -412,9 +414,9 @@ CG_EXTERN CGImageRef YYCGImageCreateDecodedCopy(CGImageRef imageRef, BOOL decode
  @param destBitmapInfo Destimation image bitmap, only support 32bit format (such as ARGB8888).
  @return A new image, or NULL if an error occurs.
  */
-CG_EXTERN CGImageRef YYCGImageCreateCopyWithOrientation(CGImageRef imageRef,
-                                              UIImageOrientation orientation,
-                                              CGBitmapInfo destBitmapInfo);
+CG_EXTERN CGImageRef _Nullable YYCGImageCreateCopyWithOrientation(CGImageRef imageRef,
+                                                                  UIImageOrientation orientation,
+                                                                  CGBitmapInfo destBitmapInfo);
 
 /**
  Create an image copy with CGAffineTransform.
@@ -425,10 +427,10 @@ CG_EXTERN CGImageRef YYCGImageCreateCopyWithOrientation(CGImageRef imageRef,
  @param destBitmapInfo Destimation image bitmap, only support 32bit format (such as ARGB8888).
  @return A new image, or NULL if an error occurs.
  */
-CG_EXTERN CGImageRef YYCGImageCreateAffineTransformCopy(CGImageRef imageRef,
-                                              CGAffineTransform transform,
-                                              CGSize destSize,
-                                              CGBitmapInfo destBitmapInfo);
+CG_EXTERN CGImageRef _Nullable YYCGImageCreateAffineTransformCopy(CGImageRef imageRef,
+                                                                  CGAffineTransform transform,
+                                                                  CGSize destSize,
+                                                                  CGBitmapInfo destBitmapInfo);
 
 /**
  Encode an image to data with CGImageDestination.
@@ -438,7 +440,7 @@ CG_EXTERN CGImageRef YYCGImageCreateAffineTransformCopy(CGImageRef imageRef,
  @param quality   The quality (0.0~1.0)
  @return A new image data, or nil if an error occurs.
  */
-CG_EXTERN CFDataRef YYCGImageCreateEncodedData(CGImageRef imageRef, YYImageType type, CGFloat quality);
+CG_EXTERN CFDataRef _Nullable YYCGImageCreateEncodedData(CGImageRef imageRef, YYImageType type, CGFloat quality);
 
 
 /**
@@ -468,12 +470,11 @@ CG_EXTERN NSUInteger YYImageGetWebPFrameCount(CFDataRef webpData);
                             (speed down, and may lose some details).
  @return The decoded image, or NULL if an error occurs.
  */
-CG_EXTERN CGImageRef YYCGImageCreateWithWebPData(CFDataRef webpData,
-                                       BOOL decodeForDisplay,
-                                       BOOL useThreads,
-                                       BOOL bypassFiltering,
-                                       BOOL noFancyUpsampling);
-
+CG_EXTERN CGImageRef _Nullable YYCGImageCreateWithWebPData(CFDataRef webpData,
+                                                           BOOL decodeForDisplay,
+                                                           BOOL useThreads,
+                                                           BOOL bypassFiltering,
+                                                           BOOL noFancyUpsampling);
 
 typedef NS_ENUM(NSUInteger, YYImagePreset) {
     YYImagePresetDefault = 0,  ///< default preset.
@@ -495,8 +496,10 @@ typedef NS_ENUM(NSUInteger, YYImagePreset) {
  @param preset        Preset for different image type, default is YYImagePresetDefault.
  @return WebP data, or nil if an error occurs.
  */
-CG_EXTERN CFDataRef YYCGImageCreateEncodedWebPData(CGImageRef imageRef,
-                                         BOOL lossless,
-                                         CGFloat quality,
-                                         int compressLevel,
-                                         YYImagePreset preset);
+CG_EXTERN CFDataRef _Nullable YYCGImageCreateEncodedWebPData(CGImageRef imageRef,
+                                                             BOOL lossless,
+                                                             CGFloat quality,
+                                                             int compressLevel,
+                                                             YYImagePreset preset);
+
+NS_ASSUME_NONNULL_END

+ 10 - 6
YYWebImage/Image/YYSpriteSheetImage.h

@@ -19,6 +19,8 @@
 #import "YYAnimatedImageView.h"
 #endif
 
+NS_ASSUME_NONNULL_BEGIN
+
 /**
  An image to display sprite sheet animation.
  
@@ -79,13 +81,13 @@
  
  @return An image object, or nil if an error occurs.
  */
-- (instancetype)initWithSpriteSheetImage:(UIImage *)image
-                            contentRects:(NSArray *)contentRects
-                          frameDurations:(NSArray *)frameDurations
-                               loopCount:(NSUInteger)loopCount;
+- (nullable instancetype)initWithSpriteSheetImage:(UIImage *)image
+                                     contentRects:(NSArray<NSValue *> *)contentRects
+                                   frameDurations:(NSArray<NSNumber *> *)frameDurations
+                                        loopCount:(NSUInteger)loopCount;
 
-@property (nonatomic, readonly) NSArray *contentRects;
-@property (nonatomic, readonly) NSArray *frameDurations;
+@property (nonatomic, readonly) NSArray<NSValue *> *contentRects;
+@property (nonatomic, readonly) NSArray<NSValue *> *frameDurations;
 @property (nonatomic, readonly) NSUInteger loopCount;
 
 /**
@@ -98,3 +100,5 @@
 - (CGRect)contentsRectForCALayerAtIndex:(NSUInteger)index;
 
 @end
+
+NS_ASSUME_NONNULL_END

+ 5 - 1
YYWebImage/YYImageCache.h

@@ -13,6 +13,8 @@
 
 @class YYMemoryCache, YYDiskCache;
 
+NS_ASSUME_NONNULL_BEGIN
+
 /// Image cache type
 typedef NS_OPTIONS(NSUInteger, YYImageCacheType) {
     /// No value.
@@ -52,7 +54,7 @@ typedef NS_OPTIONS(NSUInteger, YYImageCacheType) {
 ///=============================================================================
 
 /** The name of the cache. Default is nil. */
-@property (copy) NSString *name;
+@property (nullable, copy) NSString *name;
 
 /** The underlying memory cache. see `YYMemoryCache` for more information.*/
 @property (strong, readonly) YYMemoryCache *memoryCache;
@@ -216,3 +218,5 @@ typedef NS_OPTIONS(NSUInteger, YYImageCacheType) {
 - (void)getImageDataForKey:(NSString *)key withBlock:(void(^)(NSData *imageData))block;
 
 @end
+
+NS_ASSUME_NONNULL_END