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 doesn't work quickly.

So how do you suppress warnings in Swift?

+4


source to share


2 answers


EDIT: The below command is for the "deprecated declarations" warning. If you want to suppress various warnings, you must use the warning flag. Most of you are probably using Clang, and these warning flags can be found here . So if you want to suppress, for example -Wunused-argument

, you write it with no ": -Wnounused-argument

.

If you want to turn off compiler warnings, go to Project β†’ Task β†’ Build Settings and add a prefix to the flag without another warning flags:

for all files



If you want to disable the warning for a single file: Navigate to the project and select Target β†’ assembly Phases β†’ Compile sources and mark a file:

for one file

+8


source


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 disable warnings.



Cocoapods Fix:

If you are trying to suppress warnings from a problematic module, you can automatically inhibit_warnings

all warnings from a dependency using inhibit_warnings

in your subfile:

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

      

0


source







All Articles