Xcode / iOS-摆脱特定常量的弃用警告? [英] Xcode/iOS -- get rid of deprecation warnings for specific constants?

查看:158
本文介绍了Xcode / iOS-摆脱特定常量的弃用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一些不推荐使用的常量。他们需要留下来。我不想被警告,但是想要警告是否以后会在我的项目中出现其他不赞成使用的常量。

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的标头将它们声明如下:

Apple's header declares them as follows:

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

如何使警告静音?

使已弃用方法的警告静音的相关答案

此处用于静默有关不建议使用的字符串转换的警告的相关答案
此处

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

推荐答案

我知道这是一个老话题,但是今天我正在处理同样的烦恼。

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

示例:您想摆脱烦人的弃用警告,但仅出于 [[UIDevice currentDevice] uniqueIdentifier]] ,因为您很可能想在开发阶段通过TestFlight使用它。
如果您错误地使用了其他不推荐使用的声明,您仍然希望编译器向您发出警告。

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.

我喜欢sarfata的答案:它可以完成工作。但是还有更多在政治上正确的方法:

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

以下食谱取自 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.

这篇关于Xcode / iOS-摆脱特定常量的弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆