Swift /可可中的windowNibName错误? [英] windowNibName error in Swift / Cocoa?

查看:84
本文介绍了Swift /可可中的windowNibName错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这将教我开始一年半的Swift编程工作。显然情况已经改变了。



在我以前的程序中,MainWindowController内部的内容很高兴:

 类MainWindowController:NSWindowController {

覆盖var windowNibName:字符串? {
return MainWindowController
}
...

但是现在我遇到了这个错误:


类型为'String?'的属性'windowNibName'无法覆盖具有以下内容的
属性键入'NSNib.Name?'


我一直在Google搜索和搜索Stack Overflow,但一直无法弄清楚确切的含义问题是以及如何解决它。在过去的一年半中,这方面发生了什么变化?



预先感谢!

解决方案

现在将 windowNibName 的类型从 String 替换为 struct 。 / p>

您可以在此处查看更多详细信息
要纠正错误,可以使用以下代码:

  class MainWindowController:NSWindowController {

是否覆盖var windowNibName:NSNib.Name? {
return NSNib.Name( MainWindowController)
}
}




如果使用了-initWithWindowNibPath:owner:来初始化实例,则会给出最后一个扩展名为
的路径组件。如果使用了-initWithWindowNibName:[owner:],则只是
给出了该名称。




 打开var windowNibName:NSNib.Name? {get} 


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!

解决方案

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 }

这篇关于Swift /可可中的windowNibName错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆