Xcode / iOS - get rid of obsolescence warnings for certain constants?

I have some deprecated constants in my project. They need to stay. I don’t want you to be warned about them, but you want to be warned if other obsolete constants appear in my project later.

The Apple header declares them as follows:

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

How can I silence a warning?

The related answer to block the warning for the deprecated method is here
The related answer for blocking the obsolete row disclaimer warning is here

+6
source share
4 answers

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 obsolescence warning, but only for [[UIDevice currentDevice] uniqueIdentifier]] , since you most likely want to use it at design time with TestFlight. You still want the compiler to warn you if you mistakenly use some other obsolete declaration.

I like the answer of sarfata : it does the job. But there is a more politically correct way:

The 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 

Be sure to comment out these lines before creating them for distribution. Or simply use a preprocessor macro to exclude these lines from the release build.

+23
source

Add to compiler flags:

 -Wno-deprecated-declarations 

or, in Xcode, select "No" for the option to install the assembly:

 Warn About Deprecated Functions 

and then if you look at the output of the assembly (Apple + 7 in Xcode 4), you will notice the aforementioned compiler flag.

+2
source

The correct answer to this question is not to use obsolete constants. Check the documentation for the recommended way to do something now. For obsolete methods / constants / independently, there is always a link to "replace" if you want. Use this instead. This way, your code does not mysteriously break when they disappear forever, but your users still have an assembly built against the old sdk, and now their code crashes or, even worse, does strange things.

+1
source

This is google's # 1 answer, and I believe there are some cases of faire when using the deprecated method is useful and when you want to avoid warnings in order to keep the assembly "clean." These solutions are inspired by: http://vgable.com/blog/2009/06/15/ignoring-just-one-deprecated-warning/

The idea is to declare a new protocol that has the same method (but not deprecated, of course), and pass the object to that protocol. Thus, you can call the method without warning and not get rid of all the failure warnings.

Example. If you want to integrate TestFlight into your application, the SDK documentation assumes the transfer of a unique device identifier during BETA. This can help determine which testers are having problems. This method is deprecated by Apple (and they will not allow you to submit the application), but I think this is a good example of using an outdated method.

In the App Delegate app:

 /* This is to avoid a warning when calling uniqueIdentifier for TestFlight */ @protocol UIDeviceHack <NSObject> - (NSString*) uniqueIdentifier; @end @implementation MyAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [TestFlight takeOff:@"Your-Testflight-team-id"]; // TODO: Remove this in production (forbidden APIs) - Used here to improve beta reporting. [TestFlight setDeviceIdentifier:[(id<UIDeviceHack>)[UIDevice currentDevice] uniqueIdentifier]]; // ... } 
+1
source

Source: https://habr.com/ru/post/891370/


All Articles