Pointer is missing a nullability type specifier

后端 未结 6 1811
情书的邮戳
情书的邮戳 2021-01-31 01:17

In Xcode 7 GM I started to get this warning:

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

6条回答
  •  攒了一身酷
    2021-01-31 01:52

    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;
    

    Why? It's due to Swift. Swift allows optional parameters (?), which Objective-C does not. This is done as a bridge between the both of them for the Swift compiler to know those parameters are optional. A 'Nonnull' will tell the Swift compiler that the argument is the required. A nullable that it is optional

    For more info read: https://developer.apple.com/swift/blog/?id=25

提交回复
热议问题