If I have a swift subclass that:
self
self
Do
No, you don't have to.
Assume you have the following classes.
class a {
let name: String
init() {
name = "james"
}
}
class b: a {
let title: String
override init() {
title = "supervisor"
}
}
If you instantiate a variable with
let myVar = b()
Then,
override init()
in b
will be calledinit()
in a
will be calledEven though you didn't explicitly call super.init()
.
This has been confirmed by Chris Laettner on the swift-user's email list. It kicks in when your super class has a single designated initializer with a zero-argument init. This is why you don’t have to call super.init() when deriving from NSObject.
*Thanks to Wingzero's comment below