0

I am getting this error message and I don't understand why. This is from a project I inherited that is using this pod called SwiftyOnboardOverlay.I read similar questions but none seem to fix the issue for me.

The name for the superclass init is the same as the one I am getting the error as you can see.

Error Message: "Initializer does not override a designated initializer from its superclass"

class WalkthroughOverlay: SwiftyOnboardOverlay {
...

 override init(frame: CGRect) {//error here
    super.init(frame:frame)
        setupViews()
    }
required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}


...
}

And the parent initializers

open class SwiftyOnboardOverlay: UIView {

   override init(frame: CGRect) {
        super.init(frame: frame)
        setUp()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }


}

Edit 1:

Screenshots:

enter image description here

enter image description here

What's going on here? Thanks for any help.

Edit2:

Ok so the previous dev also had these extensions with convenience initializers:

extension UIView {
    /// EZSwiftExtensions
    public convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat) {
        self.init(frame: CGRect(x: x, y: y, width: w, height: h))
    }

    /// EZSwiftExtensions, puts padding around the view
    public convenience init(superView: UIView, padding: CGFloat) {
        self.init(frame: CGRect(x: superView.x + padding, y: superView.y + padding, width: superView.w - padding*2, height: superView.h - padding*2))
    }

    /// EZSwiftExtensions - Copies size of superview
    public convenience init(superView: UIView) {
        self.init(frame: CGRect(origin: CGPoint.zero, size: superView.size))
    }
}
JP Aquino
  • 3,946
  • 1
  • 23
  • 25
  • I copied your code into a Swift playground. I removed the calls to `setup` and `setupViews`. The only error I get is that `WalkthroughOverlay` needs to implement the required `init?(coder:)` method. – rmaddy Sep 16 '17 at 20:45
  • Possible duplicate of [Initializer does not override a designated initializer from its superclass](https://stackoverflow.com/questions/29031270/initializer-does-not-override-a-designated-initializer-from-its-superclass) – mfaani Sep 16 '17 at 20:46
  • Thanks rmaddy. Edited the question. The init?(coder:) is implemented. – JP Aquino Sep 16 '17 at 20:49
  • Thanks Honey. I looked over the answers there but couldn't find an answer. – JP Aquino Sep 16 '17 at 20:50
  • Now there is no error after removing the calls to `setup` and `setupViews`. Do you still get an error if you comment out those lines? – rmaddy Sep 16 '17 at 20:50
  • 1
    Yes its a code I inherited like I said. That init is not in the classes I showed but I will look for it now. You seem stressed matt. That IS real code and I just didn't want to paste the entire class so I copy-pasted what I thought was relevant. – JP Aquino Sep 16 '17 at 21:04
  • 1
    Could it be that you need to add the "public" keyword to your subclass's required init?() definition ? I remember reading somewhere that you cannot give lower access to the override than that of superclass's function. (or just remove public from the first subclass' init?() given that it is open) – Alain T. Sep 16 '17 at 21:15
  • Thanks Alain but that does not seem to fix the issue. – JP Aquino Sep 16 '17 at 21:23
  • Could it be because it's in another module and SwiftyOnboardOverlay.init(frame:) is not visible? – algrid Sep 16 '17 at 21:26
  • Ok Solved. Alain your comment got me on the way to solve this. I needed to use the public keyword on the superclass init(frame:CGRect) initializer. – JP Aquino Sep 16 '17 at 21:32
  • @AlainT. I think you are referring to [Liskov substitution principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle) – mfaani Sep 16 '17 at 21:51

1 Answers1

0

Ok so I needed to add the public keyword to the superclass init method to make this work:

override public init(frame: CGRect) {
    super.init(frame: frame)
    setUp()
}
JP Aquino
  • 3,946
  • 1
  • 23
  • 25