Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling a specific warning in a specific line in Xcode

I'm writing an iPhone app against the Base 4.0 SDK, but I'm targeting OS 3.1.3 so OS 3 users can use the app.

I call:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 

which is deprecated in iOS 4.0. I'm aware of this, and have measures in place to call the newer "withAnimation" version if we are running under iOS 4.0 or greater.

However, I'm getting a warning that I'm calling a deprecated SDK.

I'd like to disable this specific warning in this specific place. I want all other warnings (including the same deprecated warning in other locations)

Can this be accomplished in Xcode?

like image 531
David Coufal Avatar asked Jun 29 '10 02:06

David Coufal


People also ask

How do I turn off warnings 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).


2 Answers

For CLANG, this works:

#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations"   // Here I like to leave a comment to my future self to explain why I need this deprecated call   NSString *myUDID = [[UIDevice currentDevice] uniqueIdentifier]; #pragma clang diagnostic pop 

You can use it inside a method, which allows you to be very specific about the line that causes the warning you want to have ignored.

like image 177
Guillaume Avatar answered Sep 20 '22 21:09

Guillaume


You might be able to use GCC pragmas. This should disable the deprecated warning for the enclosed function.

#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated" -(void)foo{     // As Georg Fritzsche notes below, the pragmas only work outside of functions     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; } #pragma GCC diagnostic pop 

I don't know if this will work with Clang, but it should work with GCC.

Basically, it saves the state of the warnings/errors, disables the deprecated warning, compiles the function, then restores the state of the diagnostics.

like image 37
paxswill Avatar answered Sep 21 '22 21:09

paxswill