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

Viewed 4361

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

4 Answers

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

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.

Related