问题
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