从Xcode 9.3开始的nullability-completeness警告

时间:2018-06-27 10:46:44

标签: ios objective-c xcode clang

The "nullability-completeness" warning对我而言不适用于Xcode 9.3(和9.4.1)。 虽然可以在Xcode 9.1和9.2中使用。

我使用“ Single View App”模板在Xcode 9.2(或9.1)中创建了一个新的iOS项目,然后将此方法添加到ViewController.h:

- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;

我在每个参数上收到2条警告,如下所示:

In file included from /Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.m:9:
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;
                              ^
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: note: insert '_Nullable' if the pointer may be null
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;
                              ^
                               _Nullable
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: note: insert '_Nonnull' if the pointer should never be null
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;

但是,如果我在Xcode 9.3(或9.4.1)中打开并重建该项目,则不会收到这些警告。

我尝试进入构建设置并显式启用此标志(尽管默认情况下应启用该标志),但仍然无济于事:

enter image description here

2 个答案:

答案 0 :(得分:0)

此问题已在Xcode 10.2中修复,它会再次发出正确的警告。

答案 1 :(得分:-1)

解决方案非常简单(无需提交错误)。


  

在项目构建设置中,只需搜索“自定义编译器”   标志”,并添加以下内容:

     

-Wno-nullability-completeness

enter image description here