Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode/iOS -- get rid of deprecation warnings for specific constants?

I have some deprecated constants in my project. They need to stay. I don't want to be warned about them, but do want to be warned if other deprecated constants should turn up in my project later.

Apple's header declares them as follows:

extern NSString * const NameOfStringConstant __OSX_AVAILABLE_BUT_DEPRECATED(version availability info here)

How can I silence the warning?

Related answer for silencing the warning for a deprecated method here
Related answer for silencing the warning about a deprecated string conversion here

like image 874
William Jockusch Avatar asked Jun 26 '11 02:06

William Jockusch


2 Answers

Add to the compiler flags:

-Wno-deprecated-declarations

or, in Xcode, select "No" for the build setting option:

Warn About Deprecated Functions

and then if you look at the build output (Apple+7 in Xcode 4), you'll notice the aforementioned compiler flag.

like image 31
senojsitruc Avatar answered Mar 16 '23 00:03

senojsitruc


I know this is an old topic but today i was dealing with the same annoyance.

Example: you want to get rid of the annoying deprecation warning but just for [[UIDevice currentDevice] uniqueIdentifier]] since you most probably want to use it in development phase with TestFlight. You'd still want the compiler to warn you if you use some other deprecated declaration by mistake.

I like sarfata's answer: it does the job. But there's more politically correct way available:

Following recipe is taken from The Goo Software Blog.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];
#pragma clang diagnostic pop

Make sure you comment out this lines before building for distribution. Or simply use a preprocessor macro to exclude this lines from a release build.

like image 140
Rok Jarc Avatar answered Mar 15 '23 23:03

Rok Jarc