Reputation: 1949
I'm trying to load a ViewController on my appDelegate class. Like this:
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var viewController = HomeViewController()
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.window.backgroundColor = NSColor(rgba: "#02303A")
self.viewController.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame))
self.window.contentView?.addSubview(self.viewController.view)
}
}
My view controller is very simples, just:
import PureLayout
class HomeViewController : NSViewController {
let search : NSSearchField = {
let search = NSSearchField.newAutoLayoutView()
return search
}()
override func loadView() {
super.loadView()
self.view.layer?.backgroundColor = NSColor.blackColor().CGColor
self.view.addSubview(search)
}
}
But when the I compile the project, the log returns:
The repository with the complete source code: Github
Anyone know what can be? I do this on my iOS projects and it works fine.
Upvotes: 2
Views: 986
Reputation: 3155
(Build your user interface for the view controller in this view, rather than the one in your main nib.)
Upvotes: 2