I'm using Swift 3 to override an init method that initializes my Navigation Controller with a rootviewcontroller (and set the rootviewcontroller delegate to self). But, I'm getting the following error:
Incorrect argument label in call (have 'rootViewController:', expected 'coder:')
class NavigationController: UINavigationController, RootViewControllerDelegate {
let rvc = RootViewController()
convenience init() {
self.init(rootViewController: rvc) // Incorrect argument label in call (have 'rootViewController:', expected 'coder:')
self.rvc.delegate = self
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
Can somebody explain what I'm doing wrong please? I initially tried using
override func init()
but Xcode ultimately had me convert that to
convenience init()
The init(rootViewController:)
is defined in UINavigationController
, which is the super class of your NavigationController
class. Therefore, you should use super
instead of self
to refer to it:
init() {
super.init(rootViewController: rvc)
self.rvc.delegate = self
}
Since you have one other initializer defined in NavigationController
, Xcode thinks that you were trying to call that initializer. That's why it tells you to put coder:
as the argument label.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With