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
There are a number of things you could do here, but the simplest would probably to rewrite your code just a tad.
Casting the view variable to id before sending the message should ensure that so long as a method named
-title
exists anywhere, it'll stay silent.Another option:
This is a little different from the above, in that it doesn't require the file to "see" any method named title; but it's a bit more wordy.
Edit: I'm aware that neither of these approaches actually turn of warnings for any amount of time, but rather suppress them.
Suppression, when done correctly, at least, is usually better than simply ignoring.
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
The closest way to do what you want is to use the GCC diagnostic pragma. See this question for details.