How to suppress warnings in Swift 3?

2019-05-05 09:20发布

Using clang* I could do

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   // ...
#pragma clang diagnostic pop

However this does not work in swift.

So how to do suppress warnings in Swift?

2条回答
Root(大扎)
2楼-- · 2019-05-05 09:33

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.

If you want to disable compiler warnings then go to Project -> Target -> Build Settings and add flag with no prefix to other warning flags:

for all files

If you want to disable warnings for separate file: Go to Project and pick relevant Target -> Build Phases -> Compile Sources and flag separate file:

for one file

查看更多
时光不老,我们不散
3楼-- · 2019-05-05 09:35

This works for Xcode 10.2+ and 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.

Cocoapods Fix:

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 'Kingfisher', '~> 4.6', :inhibit_warnings => true
查看更多
登录 后发表回答