描述你的问题
Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
警告如上
程序运行正常,全部加上__nonnull 就好了,为什么?
贴上相关代码
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文件
贴上相关截图
已经尝试过哪些方法仍然没解决(附上相关链接)
//NS_ASSUME_NONNULL_BEGIN
//NS_ASSUME_NONNULL_END
使用这个只能消除属性警告
巴扎黑2017-04-17 17:32:11
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);
解决就两种方法:
去掉_Nullable
关键字。反正默认就是 nullable 的,去掉也没什么关系。
勤快一点就留着_Nullable
关键字,然后把报 warning 的每个属性和参数都加上_Nonnull
、_Nullable
和_Null_unspecified
。
注意像你说的『全部加上__nonnull 就好了』这样是不安全的,最好是根据这个属性到底有没有可能是 null 再选择加 nonnull 还是 nullable,没时间一个一个看的话,也应该全加_Null_unspecified
,不能全加__nonnull
rrreee
_Nullable
keyword. Anyway, the default is nullable, so it doesn’t matter if you remove it. 🎜🎜
_Nullable
keyword, and then add _Nonnull
and _Nullable
to each attribute and parameter of the warning. and _Null_unspecified
. _Null_unspecified
, but not all __nonnull
. 🎜🎜
🎜PHP中文网2017-04-17 17:32:11
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