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 ?
4 Answers
Move :
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//...
}
to the ViewController
file directly.
It is independent of the UIPopoverPresentationControllerDelegate
protocol.

- 6,676
- 3
- 36
- 55
-
1That0s the right answer. Thanks mate, you've saved my day :D – DungeonDev Jun 06 '19 at 12:51
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?) {
//...
}

- 1,232
- 12
- 23
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

- 3,253
- 1
- 16
- 33
-
But the super class is UIViewController, I cannot make change to Apple's UIKit – guocongyu Sep 27 '17 at 02:08
-
And why override viewDidLoad() etc. works, only this method doesn't work – guocongyu Sep 27 '17 at 02:12
-
This isn't a problem with UIKit. Is `SegueIdentifier` or `VirtualObjectSelectionViewController` marked as being `@available(iOS 11, *)`? If so, try wrapping your use of those in an `if #available` block – Michael Hulet Sep 27 '17 at 02:16
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.

- 684
- 6
- 12