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?

Meniny
  • 570
  • 5
  • 18
  • 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 '17 at 03:50
  • @anonman yes that's absolutely right. I'm just wondering how to do this in swift. – Meniny Apr 22 '17 at 03: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 '17 at 04:03

2 Answers2

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

Wladek Surala
  • 2,392
  • 1
  • 23
  • 30
  • Doesn't work for me. The warning messages are still shown. The version of my Xcode is 8.3.3. – Bagusflyer Nov 06 '17 at 02: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? – Wladek Surala Nov 06 '17 at 15:19
  • @ZhouHao can you provide a bit more information about your project? How many targets do you have? Do you use cocoapods? – Wladek Surala Nov 07 '17 at 10:01
  • 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: https://stackoverflow.com/questions/31540446/how-to-silence-a-warning-in-swift – micnguyen Nov 14 '17 at 00:22
  • @WladekSurala I have 4 targets. Yes, I use cocoapods. – Bagusflyer Jan 02 '18 at 04:40
  • I am unable to find a list of what the warning are actually called, any ideas where to find one? I am currently getting warnings for `Overlapping Access` but i cannot find the correct flag. `-Wnooverlapping-access` does not work – Joe Maher Apr 04 '18 at 22:05
  • 1
    @JoeMaher check out this list of warnings for clang: http://www.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:) – Wladek Surala Apr 11 '18 at 09: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 '18 at 00:07
  • This eliminates all warning of that type in a file, but what if you just want a single line to be excused of a certain warning? – Moshe Gottlieb Aug 27 '19 at 13:51
-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
N S
  • 2,431
  • 6
  • 30
  • 39
  • 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. – Simon Bengtsson Apr 17 '19 at 12:46