如何覆盖Xcode中的弃用警告?

ohh*_*hho 5 iphone xcode objective-c compiler-warnings

是否有#pragma覆盖编译时警告,例如:

warning: 'ADBannerContentSizeIdentifier480x32' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/iAd.framework/Headers/ADBannerView.h:111)
Run Code Online (Sandbox Code Playgroud)

我必须通过以下方式保持4.2之前iOS设备的兼容性:

NSString *iAdSize = (osVersion >= 4.2) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier480x32;
Run Code Online (Sandbox Code Playgroud)

谢谢

ody*_*yth 8

就在这里

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wno-deprecated-declarations"
//deprecated function
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

如果您想知道某个错误的正确语法是什么,只需在Xcode中找到它,然后查看快速帮助

在此输入图像描述

  • 我不得不使用#pragma clang诊断忽略"-Wdeprecated-declarations"才能工作. (4认同)

Ken*_*ger 2

有一个构建设置可以切换已弃用函数的警告。

尽管执行此操作的正确方法是在运行时检查操作系统版本,并在必要时执行已弃用的方法,否则执行新方法。