ios - 使用typedef 属性出现Pointer is missing a nullability type specific 的警告
PHPz
PHPz 2017-04-17 17:30:11
0
2
860
  1. 描述你的问题

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

警告如上
程序运行正常,全部加上__nonnull 就好了,为什么?

  1. 贴上相关代码

typedef void (^completionHandlerBlock)(NSURL * _Nullable localfile, NSURLResponse * _Nullable response, NSError * _Nullable error);
//NS_ASSUME_NONNULL_BEGIN
@interface DownLoadImages : NSObject

@property (nonatomic, strong) NSURL *imageURL;

- (instancetype)initWithURL:(NSURL *)contentURL;
- (void)startDownloadingImage:(completionHandlerBlock)completionHandler;
@end

.h文件

  1. 贴上相关截图

  2. 已经尝试过哪些方法仍然没解决(附上相关链接)
    //NS_ASSUME_NONNULL_BEGIN

//NS_ASSUME_NONNULL_END
使用这个只能消除属性警告

PHPz
PHPz

学习是最好的投资!

reply all(2)
巴扎黑

This is not because of typedef, but because the _Nullable keyword appears in the block you defined. If you remove it, the warning will not be reported: typedef的问题,是你定义的 block 里面出现了_Nullable关键字。如果你去掉就不会报 warning 了:

typedef void (^completionHandlerBlock)(NSURL * localfile, NSURLResponse * response, NSError * error);

解决就两种方法:

  1. 去掉_Nullable关键字。反正默认就是 nullable 的,去掉也没什么关系。

  2. 勤快一点就留着_Nullable关键字,然后把报 warning 的每个属性和参数都加上_Nonnull_Nullable_Null_unspecified
    注意像你说的『全部加上__nonnull 就好了』这样是不安全的,最好是根据这个属性到底有没有可能是 null 再选择加 nonnull 还是 nullable,没时间一个一个看的话,也应该全加_Null_unspecified,不能全加__nonnull rrreee

    There are two solutions:
    Remove the _Nullable keyword. Anyway, the default is nullable, so it doesn’t matter if you remove it. 🎜🎜
  3. 🎜Be diligent and keep the _Nullable keyword, and then add _Nonnull and _Nullable to each attribute and parameter of the warning. and _Null_unspecified.
    Note that it is unsafe as you said "just add __nonnull to everything". It is best to choose whether to add nonnull or nullable based on whether the attribute may be null. If you don't have time to look at them one by one, You should also add all _Null_unspecified, but not all __nonnull. 🎜🎜 🎜
Ty80

This is a new feature added in the version of xcode6.3. As long as you use this attribute, it means that all parameters of the variables and methods in the class must be considered and this attribute must be set

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template