用于抑制可空性警告的 Xcode 编译标志不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37691049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:52:10  来源:igfitidea点击:

Xcode Compile Flag to Suppress Nullability Warnings not Working?

iosobjective-cxcode

提问by electronix384128

For a limited time I want to suppress these kind of warnings the compiler is showing me in Xcode 7.3.1:

在有限的时间内,我想抑制编译器在 Xcode 7.3.1 中向我显示的此类警告:

<File>: Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

<File>: Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

I have added this compiler flag to all classes under My Target/Build Phases/Compile Sources: -Wnullability-completeness

我已将此编译器标志添加到我的目标/构建阶段/编译源下的所有类: -Wnullability-completeness

But it's not working - the warnings are still shown. How can I get rid of the warnings?

但它不起作用 - 仍然显示警告。我怎样才能摆脱警告?

回答by Carl Norum

To disablethose warnings, you want: -Wno-nullability-completeness. Note the no-; the flag you're using enablesthose warnings.

禁用这些警告,你想要的:-Wno-nullability-completeness。注意no-; 您使用的标志启用了这些警告。

回答by RunLoop

Note that in Xcode 11 it is now -Wno-nonnull

请注意,在 Xcode 11 中,它现在是 -Wno-nonnull

It should be set in "Other Warning Flags" in the "Apple Clang - Custom Compiler Flags" section of your target.

它应该在目标的“Apple Clang - 自定义编译器标志”部分的“其他警告标志”中设置。

You could also avoid these warnings and setting the above altogether by removing these flags Xcode automatically adds to new header files in Objective-C:

您还可以通过删除 Xcode 自动添加到 Objective-C 中的新头文件的这些标志来避免这些警告并完全设置上述内容:

NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END

回答by Steven Kramer

In Xcode 11.3, these started appearing out of nowhere in my pure Swift project on the Github ci. That was because I am importing the AWS Objective-C SDK.

在 Xcode 11.3 中,这些开始出现在我在 Github ci 上的纯 Swift 项目中。那是因为我要导入 AWS Objective-C SDK。

Confoundingly, this would only occur on the first build, probably creating the module map for the framework. Hence it was only a problem on ci because of the clean builds.

令人困惑的是,这只会发生在第一次构建时,可能会为框架创建模块映射。因此,由于干净的构建,这只是 ci 上的一个问题。

Fixed it by adding this to the Swiftcompiler options (search for OTHER_SWIFT_FLAGSin your build settings):

通过将其添加到Swift编译器选项来修复它(OTHER_SWIFT_FLAGS在您的构建设置中搜索):

-Xcc -Wno-nullability-completeness

回答by Vlad

Settings for Xcode 11.5 when using project with mixed sources, ObjC and Swift:

使用带有混合源、ObjC 和 Swift 的项目时,Xcode 11.5 的设置:

WARNING_CFLAGS = $(inherited) -Wno-nullability-completeness
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -Wno-nullability-completeness