Ios 指针在函数接口上缺少nullability类型说明符
最初,我有一些非常简单的事情如下。Ios 指针在函数接口上缺少nullability类型说明符,ios,objective-c,Ios,Objective C,最初,我有一些非常简单的事情如下。UIAlertAction的自定义类别,这样我就可以通过[UIAlertAction okay]创建一个okay操作 @interface UIAlertAction (Custom) + (UIAlertAction *)okay; @end @implementation UIAlertAction (Custom) + (UIAlertAction *)okay { return [UIAlertAction actionWithTitle:@"
UIAlertAction
的自定义类别,这样我就可以通过[UIAlertAction okay]
创建一个okay操作
@interface UIAlertAction (Custom)
+ (UIAlertAction *)okay;
@end
@implementation UIAlertAction (Custom)
+ (UIAlertAction *)okay
{
return [UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleCancel
handler:nil];
}
@end
后来,我决定我也想要一个完整的hander,所以界面变成这样:
@interface UIAlertAction (Custom)
+ (UIAlertAction *)okay;
+ (UIAlertAction *)okayWithHandler:(void (^ __nullable)(UIAlertAction *action))handler;
@end
我开始在第一行收到警告信息:
指针缺少nullability类型说明符
我想我理解nullable的概念(老实说,这个名字很有描述性)。但我不明白的是,为什么在第二个函数上添加一个\uu nullable
会使第一个函数需要一个nullable说明符
但我不明白的是,为什么在第二个函数上添加一个uu-nullable会使第一个函数需要一个可为null的说明符
这仅仅是因为,只要在头中提供任何可空性信息,就需要为该头中的所有内容提供可空性信息。就可空性而言,要么未指定整个API,要么指定了整个API。编译器只是警告您,您的工作已经完成了一半。非常感谢!现在我明白了为什么我开始在一节课上收到如此多的警告。我只是碰巧从另一个项目复制了一些方法声明,该项目有一些
\uuu可空的声明。我刚刚删除了那个声明,所有的警告都消失了!