无法覆盖' init'已被标记为不可用

时间:2018-05-27 17:01:51

标签: 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.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
} }

1 个答案:

答案 0 :(得分:0)

NSWindow does not support coding.您可能没有,也不需要实施init(coder:)。只需删除该方法;无论如何,你没有做任何事情。