在 Xcode 中,如何抑制特定源文件中的所有警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6921884/
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-09 04:03:10  来源:igfitidea点击:

In Xcode, how to suppress all warnings in specific source files?

xcodewarnings

提问by Bobrovsky

In my application I use 3rd party code that triggers some warnings. I reviewed them and they can be safely ignored.

在我的应用程序中,我使用触发一些警告的 3rd 方代码。我查看了它们,可以安全地忽略它们。

Now I want to "mark" a file somehow, so Xcode won't show any warnings for the code in that file.

现在我想以某种方式“标记”一个文件,因此 Xcode 不会对该文件中的代码显示任何警告。

How should I do that?

我该怎么做?

回答by Jon Reid

Select your target and show Build Phases. Then enter the name of the file in the search box, and you should see it listed in the Compile Sources phase. Double-click in the Compiler Flags column for that file and enter -wto turn off all warnings for that file.

选择您的目标并显示构建阶段。然后在搜索框中输入文件名,您应该会看到它列在 Compile Sources 阶段。双击该文件的 Compiler Flags 列并输入-w以关闭该文件的所有警告。

回答by Spydy

Select Project in left navigator and select target go to build phase and Put -w in Build Phase of target file. It will hide all compiler warnings enter image description here

在左侧导航器中选择 Project 并选择 target go to build phase 并在目标文件的 Build Phase 中选择 Put -w。它将隐藏所有编译器警告 在此处输入图片说明

回答by Cal S

This works for Xcode 10.2+ and Swift 5

这适用于 Xcode 10.2+ 和 Swift 5

Manual fix:

手动修复:

Add -w -Xanalyzer -analyzer-disable-all-checksto the problematic file from Xcode > Project > Targets > Compile Sources > Double click the file where you want to turn off warnings.

-w -Xanalyzer -analyzer-disable-all-checks从 Xcode > Project > Targets > Compile Sources > 双击要关闭警告的文件添加到有问题的文件。

Cocoapods Fix:

Cocoapods 修复:

If you're trying to suppress warnings from a problematic pod, you can automatically suppress all warnings from the dependency with the inhibit_warningsflag in your podfile:

如果您试图抑制来自有问题的 pod 的警告,您可以使用podfile 中inhibit_warnings标志自动抑制来自依赖项的所有警告:

pod 'Kingfisher', '~> 4.6', :inhibit_warnings => true

enter image description here

在此处输入图片说明