Swift 无法覆盖';初始';它已被标记为不可用

Swift 无法覆盖';初始';它已被标记为不可用,swift,macos,Swift,Macos,必须调用超类“NSWindow”的指定初始值设定项: import Cocoa class MyWindow: NSWindow { init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSWindow.BackingStoreType, defer flag: Bool) { super.init(contentRect: contentRect, styleMask: NSWindow.S

必须调用超类“NSWindow”的指定初始值设定项:

import Cocoa

class MyWindow: NSWindow {

init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSWindow.BackingStoreType, defer flag: Bool) {
    super.init(contentRect: contentRect, styleMask: NSWindow.StyleMask(rawValue: NSWindow.StyleMask.RawValue(aStyle)), backing: bufferingType, defer: flag)

    self.titleVisibility = .hidden
}


required init?(coder: NSCoder) { // error: Cannot override 'init' which has been marked unavailable AND Failable initializer 'init(coder:)' cannot override a non-failable initializer
    super.init(coder: coder) // error: 'init(coder:)' is unavailable
} }

您可能不需要实现
init(coder:)
。只需删除该方法;无论如何,你都没有用它做任何事情。

致命错误:使用未实现的初始值设定项init(contentRect:styleMask:backing:defer:)我不知道你的意思。这是编译时错误吗?运行时错误?是什么情况导致的?