ios - 自 Xcode 9.3 以来的可空性完整性警告

标签 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)中打开并重建该项目 - 我不会收到这些警告。

我尝试进入build设置并显式启用此标志(尽管默认情况下应启用它),但仍然一无所获:

enter image description here

最佳答案

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


In your Project Build Settings simply search for "Custom Compiler Flags", and add the following:

-Wno-nullability-completeness

enter image description here


如果您尝试显示警告,请尝试添加此标志,清理并构建,然后删除该标志(清理并再次构建..)。如果这不起作用,可能

也许删除这些警告并不是一个错误,而是有目的地隐藏这些错误消息,以努力清理项目及其错误消息。

关于ios - 自 Xcode 9.3 以来的可空性完整性警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51060850/

相关文章:

ios - ios7中如何显示所有tabBar标题

ios - didBecomeActive 发布通知,我的 View Controller 从未听到它

ios - Obj-C - 如何将 id 转换为 GLfloat[]

objective-c - 预处理器表达式 Xcode 开头的无效标记

ios - 开发团队账号不支持域名

ios - 添加更多人后如何更新配置文件?

ios - 应用程序因 self.tableView.deleteRows 崩溃(在 : [indexPath], 处,: . 淡入淡出)

ios - Xcode 与 iPhone 4 开发 : The executable was signed with invalid entitlements.

Xcode 7.1 与 iOS 9.1 错误 : include of non-modular header inside framework module 'Parse.PFGeoPoint'

iOS - 如何沿路径绘制渐变