Here's the code:
import Cocoa
class MyWindowController: NSWindowController {
var name: String
override init(window: NSWindow?) {
name = "Sue"
super.init(window: window)
}
required init?(coder: NSCoder) {
name = "Dave"
super.init(coder: coder)
}
}
let controller = MyWindowController()
println("A boy named \(controller.name).") //=> "A boy named Sue."
Things I think I know:
MainWindowController is not provided a no arg default init() because MainWindowController declares a property without a default value.
NSWindowController does not have a no-arg init().
NSObject does have a no arg init().
How does the overridden designated initializer init(window: NSWindow?)
in MainWindowController get called?
@Arkku,
Just to be clear, NSWindowController's convenience init() would have to be implemented like this:
override convenience init() {
self.init(window: nil)
}
Merely inheriting init() from NSObject will not do that.