描述你的问题
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
使用这个只能消除属性警告
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 了:解决就两种方法:
去掉
_Nullable
关键字。反正默认就是 nullable 的,去掉也没什么关系。勤快一点就留着
There are two solutions:_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
.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
. 🎜🎜 🎜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