尽我所能,我无法在这里得到语法。我做错了什么?
class MainWindowController: NSWindowController {
let myThing: Thing
override convenience init ( window: NSWindow! ) {
myThing = Thing()
self.init( windowNibName: "nibText" )
}
...
}
非常感谢提前!
答案 0 :(得分:3)
myThing = Thing()
可以放置在声明属性的位置super.init
init?(coder: NSCoder)
,Xcode会很乐意为此插入模板这样的事情:
class MainWindowController: NSWindowController {
// the type of myThing will be inferred by the compiler
let myThing = Thing()
init() {
super.init(window: nil)
// load the contents of the nib, and set the owner as self, which connects the oultlets
NSBundle.mainBundle().loadNibNamed("nibText", owner: self, topLevelObjects: nil)
}
// you might no longer need this intializer
override init(window: NSWindow!) {
super.init( window: window )
}
// ...
}