objective-c - 使用@available 抑制 Objective-C 中的弃用警告

标签 objective-c cocoa cocoa-touch deprecation-warning

考虑到 Objective-C 中的 @available 命令,我希望弃用警告会像在 Swift 中一样消失。 示例:

ABPerson *abPerson = [participant ABPersonInAddressBook:[ABAddressBook addressBook]];

'meetingAttendeeWithMeetingPlanner:andABPerson:' is deprecated: first deprecated in macOS 10.11 - use contact framework

通过 @available 关闭,我可以限制 api 框架的使用,我的猜测是这会使警告静音,但事实并非如此。这是使用@available 命令的正确方法吗?如果是,是否有办法使警告静音?

if (@available(iOS 9, macOS 10.11, *)) {

}
else{
    ABPerson *abPerson = [participant ABPersonInAddressBook:[ABAddressBook addressBook]];
}

最佳答案

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
... the code using the deprecated API ...
#pragma clang diagnostic pop

关于objective-c - 使用@available 抑制 Objective-C 中的弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60082591/

相关文章:

ios以编程方式创建 View

iphone - 当 UITabBar 选项卡更改时关闭 DetailController?

ios - 错误 : "No visible @interface for ' UIAlertView' declares the selector 'initWithTitle'

objective-c - dequeueReusableHeaderFooterViewWithIdentifier 中的 Dequeing HeaderView 提示 IBoutlet

ios - 在重用的原型(prototype)单元格中多次应用渐变蒙版

ios - UItableView 选择问题

iphone - 确定长按手势识别器的位置

objective-c - NSRegularExpression 不起作用

macos - 交易收据属性 : can't find it anymore?

cocoa-touch - 如何使用UINavigationController的自定义 View 创建backBarButtomItem