NSWindowController and Swift
What better way to learn a language than to start a project with it. So, that is what I will be doing.
First order of business: Create a window and make it appear
In Objective-C, I typically would create an object that inherits from NSWindowController. In the subclasses’ init method, I like to call the initWithWindowNibName: of the super class and pass in the name of the nib file I am working with.
On the AppDelegate or wherever I need to use the window, I would create a property with the NSWindowController subclass. I like lazy instantiation and use it a lot.
This is how the code looks like:
So, how do I make a Swift version of this?
BAM!!! ⌘+b - Wait, error :(
WHY?????
I don’t know the details (yet) but when we subclass NSWindowController we need to implement the designated initializers. That is why we have all three init’s.
Question: How can keep the nib name in the NSWindowController subclass?
I like using the initWindowWithNibName: and I like to keep the name of the associated nib file in that object. I found out that there is a convenience keyword that we can use. This can help us create a convenience initializer. YAY!
⌘+b
⌘+r