Method does not override any method from its superclass swift 3.0 error [duplicate]
Asked Answered
Z

1

8

I am converting my code from swift 2.2 to swift 3.0 and i got Method does not override any method from its superclass error. Here is my code:

override class func layerClass() -> AnyClass {
        return CAShapeLayer.self
    }

Removing override leads to following error: Method 'layerClass()' with Objective-C selector 'layerClass' conflicts with getter for 'layerClass' from superclass 'UIView' with the same Objective-C selector

Zaremski answered 23/8, 2016 at 13:29 Comment(0)
L
10

layerClass is now a getter and no longer a method (as of Swift 3 or iOS 10). So you have to override the getter:

override public class var layerClass: Swift.AnyClass {
    get {
        return CAShapeLayer.self
    }
}
Labannah answered 23/8, 2016 at 13:32 Comment(3)
You can omit the explicit get { btwWorthen
Thanks @Labannah it works.Zaremski
... and now I learn why the override keyword exists. Had it not existed, this error never would have occured, and OP would have kept on going on the assumption that his method was overriding something from the super class. Neat!Bangka

© 2022 - 2024 — McMap. All rights reserved.