windowNibName error in Swift / Cocoa?


Keywords:swift 


Question: 

Well, that will teach me to set down Swift programming for a year and a half. Apparently things have changed.

In my past programs, this inside my MainWindowController was quite happy:

class MainWindowController: NSWindowController {

    override var windowNibName: String? {
        return "MainWindowController"
    }
...

But now I'm getting this error:

Property 'windowNibName' with type 'String?' cannot override a property with type 'NSNib.Name?'

I've been Googling and poking around Stack Overflow but have been unable to figure out what the exact problem is and how to fix it. What has changed over the last year and a half in this regard? Ideas would be most welcome.

Thanks in advance!


1 Answer: 

Now type of windowNibName replace to struct from String.

You can check more details here. To fix error you can use below code :

class MainWindowController: NSWindowController {

    override var windowNibName: NSNib.Name? {
        return NSNib.Name("MainWindowController")
    }
}

If -initWithWindowNibPath:owner: was used to initialize the instance, this gives the last path component with its extension stripped off. If -initWithWindowNibName:[owner:] was used this just gives that name.

    open var windowNibName: NSNib.Name? { get }