我的项目中有一些已弃用的常量。他们需要留下来。我不想收到关于它们的警告,但是如果稍后在我的项目中出现其他已弃用的常量,我确实希望收到警告。
Apple 的标头将它们声明如下:
extern NSString * const NameOfStringConstant __OSX_AVAILABLE_BUT_DEPRECATED(version availability info here)
我怎样才能消除警告?
消除已弃用方法警告的相关答案here https://stackoverflow.com/questions/2853184/suppressing-line-specific-xcode-compiler-warnings
消除有关已弃用字符串转换的警告的相关答案here https://stackoverflow.com/questions/59670/how-to-get-rid-of-deprecated-conversion-from-string-constant-to-char-warning
我知道这是一个老话题,但今天我也遇到了同样的烦恼。
示例:您想摆脱烦人的弃用警告,但只是为了[[UIDevice currentDevice] uniqueIdentifier]]
因为您很可能希望在开发阶段使用 TestFlight 来使用它。
如果您错误地使用了其他一些已弃用的声明,您仍然希望编译器发出警告。
I like 萨法塔的回答 https://stackoverflow.com/a/11960265/653513: 它可以完成工作。但还有更多政治正确可用方式:
以下食谱取自Goo 软件博客 http://blog.goosoftware.co.uk/2012/04/18/unique-identifier-no-warnings/.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];
#pragma clang diagnostic pop
确保在构建分发之前注释掉此行。或者简单地使用预处理器宏从发布版本中排除此行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)