78

There are some files in my iOS project that have some warnings, and I want to ignore those warnings. I don't want to disable warnings in the entire project (know how to do that), just some specific files. So, is there a way to completely ignore all warnings from a specific file?

I'm using LLVM 3.0 and Clang on Xcode 4.2.

2

4 Answers 4

98

I inherited a project that contained a lot of 320 code, and that code base threw several warnings and static analyzer errors at me that I had no interest in fixing since I will be removing that code from the project in the near future.

You can disable static analyzer warnings for a specific file by including the following compiler flag:

-Xanalyzer -analyzer-disable-all-checks

You can combine this with -w to disable warnings for that file as well. That has allowed me to push forward with new development while not having to be pestered with the 30 or so warnings generated by that code base.

Using the instructions from above: To use Xcode to alter a file's build flags:

  1. select the target
  2. select the build phase
  3. locate the file to modify the arguments in the "Compile Sources" phase
  4. double click its "Compiler Flags" cell to edit
  5. add "-w -Xanalyzer -analyzer-disable-all-checks" to suppress warnings and clang warnings
4
  • Fantastic. Thanks a bunch for that compiler flag, just what I needed.
    – Mike A
    Feb 9, 2012 at 18:52
  • 4
    Newer versions of clang (i.e., 4.x in iOS6) appear to have made this option -Xclang -analyzer-disable-checker
    – orj
    Jul 20, 2012 at 6:12
  • 3
    The -Xanalyzer form still works in my newly installed XCode (version 4.5.1, IOS6). The other form does not work.
    – fishinear
    Oct 4, 2012 at 16:42
  • 1
    This worked in XCode 4.5.2 to disable 'The right operand of '+' is a garbage value' in 3rd-party source (RegexKitLite.m) (Bug Report). The accepted answer did not. It would be helpful to update this answer with the difference between what -Xanalyzer, -w, and -analyzer-disable-checker do.
    – Goffredo
    Jan 16, 2013 at 16:46
76

if you're just using clang, then you should use the pragma syntax for sources you maintain (assuming it is impossible to remove the warning by altering the program appropriately).

here is the syntax:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"

char b = 'df'; // no warning.

#pragma clang diagnostic pop

if these are programs you cannot change and don't maintain, you should specify the warning(s) to disable for the file, rather than all. to disable all, you can add the per file argument -w. sources change, and some warnings do (or do not) apply with different build settings. clang's messages can tell you what flag equates to the generated warning.

To use Xcode to alter a file's build flags:

  • select the target
  • select the build phase
  • locate the file to modify the arguments in the "Compile Sources" phase
  • double click its "Compiler Flags" cell to edit
0
25

With the help of justin's answer, this is how you do

1. Locate the name of the warning.

In my case its conversion

enter image description here

2. Add a per file compiler flag build phases

Use the filter to find the name of the file in compile sources, type -Wno-[error name] e.g. -Wno-conversion

enter image description here

1
  • Hallelujah! I searched high and low for this. The syntax of the -W option doesn't appear to be documented anywhere!
    – mluisbrown
    Apr 10, 2015 at 14:34
3

You can select specific target -> Build settings, search for Inhibit All Warnings and set to YES. This will disable warnings on this target. This can be useful if you use some code like JSONKit with cocoapods, and you don't want to see how compiler cries about warnings :)

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.