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?

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130

3 Answers3

289

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.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • 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? – Bobrovsky Aug 03 '11 at 05:30
  • 11
    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-parameter` – Jon Reid Aug 03 '11 at 05:38
  • 16
    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. – Bobrovsky Aug 03 '11 at 12:06
  • 7
    Thanks for the hint, also worked for me (`-w` and LLVM). Really handy when you include thirdparty files you don't wand to modify. – user826955 Jul 28 '12 at 12:35
  • Check http://stackoverflow.com/questions/18883726/how-to-disable-arc-for-a-single-file-in-xcode-5 if you cannot find the "Compiler Flags" column. – kennytm Apr 01 '14 at 13:54
  • 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. – Daniel Ryan Aug 23 '15 at 23:21
  • 1
    @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. – Jon Reid Aug 23 '15 at 23:25
  • I'm going to give this a try (additional target): http://stackoverflow.com/a/7535475/515455 – Daniel Ryan Aug 23 '15 at 23:28
  • 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! – Maciej Swic Sep 11 '15 at 10:37
  • 11
    Does not work with Swift 2 using Xcode 7.0 and Apple LLVM 7.0 – King-Wizard Sep 19 '15 at 05:55
  • 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. – jotaEsse Apr 06 '17 at 12:43
  • @jotaEsse This flag suppresses compiler warnings, not linker warnings. – Jon Reid Apr 06 '17 at 14:29
  • 1
    @JonReid Thank you. Do you know if it is possible to suppress linker warnings from 3rd party Libraries then? – jotaEsse Apr 06 '17 at 17:02
  • @jotaEsse I don't know — and would like to know! Suggest you open a question, and leave a forwarding link here. – Jon Reid Apr 06 '17 at 17:04
  • @JonReid Suggestion taken. The question has been asked here: http://stackoverflow.com/q/43261876/2754958. Please feel free to edit it if it is unclear. – jotaEsse Apr 06 '17 at 17:21
  • @JonReid how to set -w flag for folder ? – a.masri Apr 01 '19 at 08:39
  • 1
    @a.masri I don't think there's a way to set a compiler directive on an entire folder. – Jon Reid Apr 02 '19 at 21:46
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

Waseem Sarwar
  • 2,645
  • 1
  • 21
  • 18
  • 17
    Does not work with Swift 2 using Xcode 7.0 and Apple LLVM 7.0 – King-Wizard Sep 19 '15 at 05:59
  • 2
    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. – jheriko Sep 14 '17 at 02:58
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

N S
  • 2,524
  • 6
  • 32
  • 42