我在我的ViewController类中重写了一个名为navbarRightButtonAction(button :)的方法.
class ViewController: PBViewController { override func navbarRightButtonAction(button: PBAdaptiveButton) { ... } }
这是我收到警告的地方:
Override of instance method 'navbarRightButtonAction(button:)' from extension of PBViewController depends on deprecated inference of '@objc'
然后我认为我们的问题在PBViewController类中,如下所示:
extension PBViewController: PBNavigationBarDelegate { func navbarRightButtonAction(button: PBAdaptiveButton) { print("Override this method") } }
所以我添加了@objc func navbarRightButtonAction(按钮:PBAdaptiveButton),但它没有帮助.
然后我查看了PBNavigationBarDelegate协议
protocol PBNavigationBarDelegate { func navbarRightButtonAction(button:PBAdaptiveButton) }
我添加了@objc协议PBNavigationBarDelegate,但它也没有帮助.
我不知道如何修复弃用警告.
解决方法
@objc extension PBViewController: PBNavigationBarDelegate
有关详细信息,请查看Swift Evolution的Limiting @objc
Inference,SE-0160.它包含以下有关扩展的示例:
Enabling/disabling @objc inference within an extension
There might be certain regions of code for which all of (or none of) the entry points should be exposed to Objective-C. Allow either @objc or @nonobjc to be specified on an extension. The @objc or @nonobjc will apply to any member of that extension that does not have its own @objc or @nonobjc annotation. For example:
class SwiftClass { } @objc extension SwiftClass { func foo() { } // implicitly @objc func bar() -> (Int,Int) // error: tuple type (Int,Int) not // expressible in @objc. add @nonobjc or move this method to fix the issue } @objcmembers class MyClass : NSObject { func wibble() { } // implicitly @objc } @nonobjc extension MyClass { func wobble() { } // not @objc,despite @objcmembers }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。