Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I temporary disable warnings in my objective c source file?

One project I work on has a build system that enforces no warnings.

But I have some code that needs warnings to work. Here is an example

NSString* title = @"";
if ([view respondsToSelector:@selector(title)]) {
  title = [view title];
}

After some googling I tried disable warnings for the code block by wrapping that code area with

#pragma warning disable
// my code
#pragma warning restore

Didn't work :(

Anyone know how to do this in Xcode?

Any help is appreciated.

-CV

like image 335
CVertex Avatar asked Mar 03 '11 13:03

CVertex


People also ask

How do I turn off warnings?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction. Now let's dive into the code for each compiler.

How do I supress a warning in Xcode?

If you want to disable all warnings, you can pass the -suppress-warnings flag (or turn on "Suppress Warnings" under "Swift Compiler - Warning Policies" in Xcode build settings).

How do I ignore a warning in Swift?

Actually, you can suppress these warnings by using @available in the enclosing logical structure (i.e. function/type).

How do I turn off errors in Xcode?

Select your project and select your target and show Build Phases . Search the name of the file in which you want to hide, 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. Hope it will help you.


1 Answers

#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 Log Navigator (Command+7), 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]


Edit

For clang you can use

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-ivar"
// your code
#pragma clang diagnostic pop
like image 143
Inder Kumar Rathore Avatar answered Nov 09 '22 02:11

Inder Kumar Rathore