Have a bit of confusion regarding designated and convenience initializers for UIViewController in Swift 2.0/Xcode 7beta3. Our UIViewControllers are all defined in code, there are no Nibs
Currently class A inherits from UIViewController like this
class A : UIViewController {
convenience init() {
...
self.init(nibName:nil, bundle:nil)
...
}
}
Then class B inherits from class A and should override the convenience init and call its as super.init()
class B : A {
convenience init() {
super.init()
...
}
}
The compiler does not allow this with Must call a designated initializer of the superclass '...' error on super.init()
You need to make your initializers designated, not convenience:
class A : UIViewController {
init() {
super.init(nibName:nil, bundle:nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("")
}
}
class B : A {
override init() {
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("")
}
}
That gives you the inheritance structure you're looking for.
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