48.警告Pointer is missing a nullability type specifier

在自己封装的方法时, 遇到这样的警告:

Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

一般的, 只有某些参数被指定不为空, 才会被编译器接受. 比较多的会发生在 handle/block 等参数上.

如在下面的方法中:

- (void)setObject:(nullable id)value
           forKey:(NSString *)defaultName
    objectChanged:(void(^)(NSUserDefaults *userDefaults, id value))changeHandler
    objectRamains:(void(^)(NSUserDefaults *userDefaults, id value))remainHandler;

需要改为如下:

- (void)setObject:(nullable id)value
           forKey:(nonnull NSString *)defaultName
    objectChanged:(nullable void(^)(NSUserDefaults *userDefaults, id value))changeHandler
    objectRamains:(nullable void(^)(NSUserDefaults *userDefaults, id value))remainHandler;

参考: Pointer is missing a nullability type specifier

你可能感兴趣的:(nonnull,nullable,警告)