Daniel Gomez Rico
Daniel Gomez Rico

Reputation: 15936

XCode 6 beta 4 convenience init error

It says Could not find an overload for init that accepts the supplied arguments

class MyController: UIViewController {

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

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

    convenience init() {
        self.init(nibName: "CreditOptionsView", bundle: nil)
    }

}

Why? It was working in the XCode 6 beta 2

Upvotes: 0

Views: 346

Answers (1)

Daniel Gomez Rico
Daniel Gomez Rico

Reputation: 15936

I solve it writing an empty override of the function, I don't know why swift can't find it. ex:

class MyController: UIViewController {

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

    convenience init() {
        self.init(nibName: "CreditOptionsView", bundle: nil)
    }

}

Same thing happened in a convenience init for UINavigationController and solved adding again the empty override:

class MyNavigationController: UINavigationController {

    override init(rootViewController: UIViewController) {
        super.init(rootViewController: rootViewController)
    }

    convenience init() {
        self.init(rootViewController: UIViewController())
    }
}

Upvotes: 3

Related Questions