In Xcode, how to suppress all warnings in specific source files?
Asked Answered
S

3

149

In my application I use 3rd party code that triggers some warnings. I reviewed them and they can be safely ignored.

Now I want to "mark" a file somehow, so Xcode won't show any warnings for the code in that file.

How should I do that?

Smilacaceous answered 3/8, 2011 at 5:6 Comment(0)
R
292

Select your target and show Build Phases. Then enter the name of the file in the search box, 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.

Rubyeruch answered 3/8, 2011 at 5:19 Comment(17)
Unfortunately, it didn't solve the issue. I am still get warnings for the file. Should -w turn off all the warnings or just a subset of possible warnings?Smilacaceous
Hmm, I expected -w to turn off all warnings, but perhaps the new compiler doesn't pay attention to that. In that case, turn off individual warnings. Find the warning in question in Build Settings, and show Quick Help in the Utilities view. You should see a description, with a -Wname-of-warning syntax. Prepend "no-" to the name and specify that in Compiler Flags. Example: to turn off -Wunused-parameter specify -Wno-unused-parameterRubyeruch
It turns out that all this is compiler-dependent. I mean, in one project that uses LLVM GCC compiler -w does the trick and in other project that uses plain GCC compiler -Wno-name-of-warning is the only way to go.Smilacaceous
Thanks for the hint, also worked for me (-w and LLVM). Really handy when you include thirdparty files you don't wand to modify.Peroxidase
Check #18884226 if you cannot find the "Compiler Flags" column.Ghostly
Can't really do this for autogenerated code. I would have to do it for hundreds of files, which could change their name when they get autogenerated again.Vedda
@Zammbi Since the code is auto-generated, fix it to generate code free of warnings. If you can't do that, auto-patch the Xcode project to set the compiler flag.Rubyeruch
I'm going to give this a try (additional target): https://mcmap.net/q/89277/-make-xcode-ignore-llvm-build-warnings-in-3rd-party-projectVedda
If you have multiple targets and a file is included in more than one target, you must add the flag to each targets "Compile Sources" phase!Sod
Does not work with Swift 2 using Xcode 7.0 and Apple LLVM 7.0Aryn
What if the libraries are static? I only have a thirdPartyLibraryFile.a under the "Build Phases" > "Link Binary With Libraries". There is no compiler flags option under that section.Annamariaannamarie
@Annamariaannamarie This flag suppresses compiler warnings, not linker warnings.Rubyeruch
@JonReid Thank you. Do you know if it is possible to suppress linker warnings from 3rd party Libraries then?Annamariaannamarie
@Annamariaannamarie I don't know — and would like to know! Suggest you open a question, and leave a forwarding link here.Rubyeruch
@JonReid Suggestion taken. The question has been asked here: https://mcmap.net/q/89278/-how-to-disable-linker-warnings-from-static-libraries-on-xcode/2754958. Please feel free to edit it if it is unclear.Annamariaannamarie
@JonReid how to set -w flag for folder ?Geri
@Geri I don't think there's a way to set a compiler directive on an entire folder.Rubyeruch
W
6

Select Project in left navigator and select target go to build phase and Put -w in Build Phase of target file. It will hide all compiler warnings enter image description here

Wildfire answered 19/8, 2014 at 11:23 Comment(2)
Does not work with Swift 2 using Xcode 7.0 and Apple LLVM 7.0Aryn
passing clang compiler flags to a foreign compiler doesn't work. quelle surprise... google the warning flag for the swift compiler and add that instead.Contentious
U
5

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

enter image description here

Unexpected answered 6/4, 2019 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.