Is there a way to suppress warnings in Xcode? Is there a way to suppress warnings in Xcode? xcode xcode

Is there a way to suppress warnings in Xcode?


To disable warnings on a per-file basis, using Xcode 3 and llvm-gcc-4.2 you can use:

#pragma GCC diagnostic ignored "-Wwarning-flag"

Where warning name is some gcc warning flag.

This overrides any warning flags on the command line. It doesn't work with all warnings though. Add -fdiagnostics-show-option to your CFLAGS and you can see which flag you can use to disable that warning.


there is a simpler way to suppress Unused variable warnings:

#pragma unused(varname)

EDIT:source: http://www.cocoadev.com/index.pl?XCodePragmas

UPDATE:I came accross with a new solution, a more robust one

  1. Open the Project > Edit Active Target> Build tab.
  2. Under User-Defined: find (or create if you don't find one )the key : GCC_WARN_UNUSED_VARIABLE set it to NO.

EDIT-2Example:

BOOL ok = YES;NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);

the compiler shows unused variable warning for ok.

Solution:

BOOL ok = YES;#pragma unused(ok)NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);

PS: You can also set/reset other warning:GCC_WARN_ABOUT_RETURN_TYPE : YES/NO


For gcc you can use

#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wshadow-ivar"// your code#pragma GCC diagnostic pop

You can learn about GCC pragma here and to get the warning code of a warning go to the Report Navigator (Command+9), select the topmost build, expand the log (the '=' button on the right), and scroll to the bottom and there your warning code is within square brackets like this [-Wshadow-ivar]

For clang you can use

#pragma clang diagnostic push#pragma clang diagnostic ignored "-Wshadow-ivar"// your code#pragma clang diagnostic pop