BWWalkthrough icon indicating copy to clipboard operation
BWWalkthrough copied to clipboard

Problem with init() when subclassing BWWalkthrough

Open wonathanjong opened this issue 6 years ago • 1 comments

While trying to implement the cocoa pod, BWWalkthrough, into my current project programmatically, I ran into a problem with the init functions/inheritance.

I tried to subclass BWWalkThroughViewController in my own class GetStartedViewController where I define buttons and pagecontrollers.

Here is the code from BWWalkThroughViewController which is a subclass of UIViewController:

class BWWalkThroughViewController: UIViewController {
    required public init?(coder aDecoder: NSCoder) {
        // Setup the scrollview
        scrollview.showsHorizontalScrollIndicator = false
        scrollview.showsVerticalScrollIndicator = false
        scrollview.isPagingEnabled = true
        super.init(coder: aDecoder)
    }

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
}

But when I try and subclass BWWalkthroughViewController in my own class I get errors saying "Ambiguous reference to member 'init(coder:)'" when calling super.init(nibName, bundle) and another error (Initializer does not override a designated initializer from its superclass) when I try to override the init(nibname, bundle):

import BWWalkthrough

class GetStartedViewController: BWWalkthroughViewController  {

required public init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

public init(){
    super.init(nibName: nil, bundle: nil) <== ERROR (Ambiguous reference to member 'init(coder:)')
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) <== ERROR (Initializer does not override a designated initializer from its superclass) {
    super.init(nibName: nil, bundle: nil) <== ERROR (Ambiguous reference to member 'init(coder:)')
}
}

I've tried different variations of containing just the public init or just the override init and not both, so I included both to show the error.

Even when I use autocomplete to call super.init, all that shows up is the function with parameters of nscoder rather than with nibName and bundle.

Can someone please help me understand why this error is happening and how to fix it? I don't understand why I can't call super.init(nibName, bundle) or override the function.

Also, if anyone else has experience implementing BWWalkthrough programmatically and/or subclassing BWWalkthroughViewController without this init bug, any help would be appreciated :)

wonathanjong avatar Jul 22 '18 04:07 wonathanjong

Getting same issue

jeanbaptistebeau avatar Sep 21 '21 15:09 jeanbaptistebeau