Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing line specific XCode compiler warnings

Similar to Ben Gottlieb's question, I have a handful of deprecated calls that are bugging me. Is there a way to suppress warnings by line? For instance:

 if([[UIApplication sharedApplication]
  respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {

  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
 } else {
  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; //causes deprecation warning
 }

All I care about is that line. I don't want to turn off all deprecation warnings. I would also rather not do something like suppress specific warnings by file.

There have been a few other circumstances where I wanted to flag a specific line as okay even though the compiler generates a warning. I essentially want to let my team know that the problem has been handled and stop getting bugged about the same line over and over.

like image 350
MrHen Avatar asked May 17 '10 22:05

MrHen


People also ask

How do I supress a warning 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.

How do I ignore a warning in C++?

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.


1 Answers

Vincent Gable has posted an interesting solution. In short:

@protocol UIApplicationDeprecatedMethods
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated;
@end

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; 
} else { 
    id<UIApplicationDeprecatedMethods> app = [UIApplication sharedApplication];
    [app setStatusBarHidden:YES animated:NO];
}
like image 115
mbauman Avatar answered Nov 02 '22 22:11

mbauman