kelin kelin - 3 months ago 42
iOS Question

Pointer is missing a nullability type specifier

In Xcode 7 GM I started to get this warning:


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


In the following function declaration (NSUserDefaults extension)

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


Why this warning is showing and how should I fix it?

Answer

You need to specify nullable also for the handlers/blocks

- (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;