5

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?

3
  • 4
    I'm going to say warnings exist for a reason; They take notice of bad practices. Focus on fixing the warnings.
    – anonman
    Apr 22, 2017 at 3:50
  • @anonman yes that's absolutely right. I'm just wondering how to do this in swift.
    – Meniny
    Apr 22, 2017 at 3:52
  • 1
    I totally agree with anonman. ⌘-click on the affected symbol to get the declaration. In most cases there is also a suggestion about the replacement of the deprecated API.
    – vadian
    Apr 22, 2017 at 4:03

2 Answers 2

9

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

9
  • Doesn't work for me. The warning messages are still shown. The version of my Xcode is 8.3.3.
    – Bagusflyer
    Nov 6, 2017 at 2:19
  • I would like to note that the above instruction is for specific warning, which is -Wnodeprecated-declarations. If you want to suppress different warning you have to use different flag. Which warnings do you want to disable? Nov 6, 2017 at 15:19
  • 1
    Setting the Build Setting flags to disable warnings does not work for Swift projects. I have pods that are generating the -Wincomplete-umbrella error and having -Wnoincomplete-umbrella does not surpress that warnings. See: stackoverflow.com/questions/31540446/…
    – micnguyen
    Nov 14, 2017 at 0:22
  • 1
    @JoeMaher check out this list of warnings for clang: xs-labs.com/en/blog/2012/01/10/warning-flags-clang maybe you will find relevant flag for your warning, if so, post it here please:) Apr 11, 2018 at 9:30
  • 1
    I've found that @WladekSurala's answer only works with Objective-C files and I also had to change the flag to -Wno-deprecated-declarations
    – Jared
    Nov 29, 2018 at 0:07
-1

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
1
  • Doesn't work for us with xcode 10.2 and swift 5. At least not in a swift file using the deprecated INStartWorkoutIntentResponseCode.continueInApp in SiriKit. Apr 17, 2019 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.