swift 4.0: Overriding 'prepare' must be as available as declaration it overrides

时光怂恿深爱的人放手 提交于 2020-02-23 10:20:49

问题


I was trying to integrate Apple's ARKit example app into my app. As ARKit is only an additional feature, so I need to support lower versions of iOS. I added @available(iOS 11.0, *) tag to all the ARKit example app classes...It almost works except this 1 error: "Overriding 'prepare' must be as available as declaration it overrides". Any idea how can I resolve this issue ?

Xcode error image


回答1:


What worked for me was adding the @available attribute above the method like so:

    @available(iOS 11.3, *)
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         //...
    }



回答2:


Move :

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     //...
}

to the ViewController file directly.

It is independent of the UIPopoverPresentationControllerDelegate protocol.




回答3:


You're overriding a method called prepare, but you're setting it to be less available than it is in the superclass you're inheriting from. If it's public in the superclass, it needs to be public or open when you override it. Likewise, if it's available on iOS versions lower than iOS 11, your overridden implementation must be available on those same iOS versions. Make sure that you've marked your overridden method with the proper access keywords, and that it's still @available on all the iOS versions as the superclass you're inheriting from




回答4:


In my case, my sub class had "@available(iOS 6.0, *)", but my super did not. I deleted it from my sub and it worked. Also could have added to my super, but I am not supporting anything that old so I just deleted.



来源:https://stackoverflow.com/questions/46438268/swift-4-0-overriding-prepare-must-be-as-available-as-declaration-it-overrides

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!