Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings in Swift 3?

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?

like image 554
Meniny Avatar asked Apr 22 '17 03:04

Meniny


People also ask

How do I turn off warnings?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction. Now let's dive into the code for each compiler.

How do I silence warnings in Xcode?

Select your project and select your target and show Build Phases . Search the name of the file in which you want to hide, and you should see it listed in the Compile Sources phase. Double-click in the Compiler Flags column for that file and enter -w to turn off all warnings for that file. Hope it will help you.

How do I turn on warnings in Xcode?

There is another approach to turning warning settings “up to eleven,” and that's to specify -Weverything in “Other Warning Flags.” This turns on all the visible Xcode warnings, along with other Clang compiler warnings that Apple has not made visible in the Xcode project settings.


1 Answers

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

like image 124
Wladek Surala Avatar answered Oct 13 '22 18:10

Wladek Surala