xcode 如何抑制 Swift 3 中的警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43555004/
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
How to suppress warnings in Swift 3?
提问by Meniny
Using clang* I could do
使用 clang* 我可以做
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// ...
#pragma clang diagnostic pop
However this does not work in swift.
但是,这在 swift 中不起作用。
So how to do suppress warnings in Swift?
那么如何在 Swift 中抑制警告呢?
回答by Wladek Surala
EDIT: below instruction is for "deprecated declarations" warning. If you want to suppress different warnings then you should use flag relevant for the warning. Most of you probably use Clang, and it's warning flags can be found here. So if you want to suppress for example -Wunused-argument
you will write it with "no": -Wnounused-argument
.
编辑:下面的说明是针对“弃用声明”警告的。如果你想抑制不同的警告,那么你应该使用与警告相关的标志。你们中的大多数人可能使用 Clang,它的警告标志可以在这里找到。因此,例如,如果您想抑制,-Wunused-argument
则将其写为 " no": -Wnounused-argument
。
If you want to disable compiler warnings then go to Project-> Target-> Build Settingsand add flag with noprefix to other warning flags:
如果要禁用编译器警告,请转到Project-> Target-> Build Settings并添加没有前缀的标志到其他警告标志:
If you want to disable warnings for separate file: Go to Projectand pick relevant Target-> Build Phases-> Compile Sourcesand flag separate file:
如果要禁用单独文件的警告:转到Project并选择相关的Target-> Build Phases-> Compile Sources并标记单独的文件:
回答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-checks
to 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_warnings
flag in your podfile:
如果您试图抑制来自有问题的 pod 的警告,您可以使用inhibit_warnings
podfile 中的标志自动抑制来自依赖项的所有警告:
pod 'Kingfisher', '~> 4.6', :inhibit_warnings => true