我正在尝试继承 WKWebView。当我实现自己的初始化程序时,我收到了这个错误:
'required' initializer 'init(coder:)' must be provided by subclass of 'WKWebView'
好的,众所周知,我们必须为 UIView 的子类实现它。对于 UIView 的直接子类,它只是实现它,但使用 WKWebView 似乎并不那么简单。我遵循了 Fix-it 提示,并将此代码段添加到代码中:
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
fatalError("init(coder:) has not been implemented")
}
所以我得到了一个像下面这样的类:
import WebKit
class TSWebView : WKWebView {
let s: String
let i: Int
init(s: String, i: Int) {
self.s = s
self.i = i
super.init(frame: CGRectZero, configuration: WKWebViewConfiguration())
}
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
fatalError("init(coder:) has not been implemented")
}
}
但是,当我这样做时,我会收到以下四个其他错误:
expected declaration
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
consecutive declarations on a line must be separated by ';'
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
cannot override 'init' which has been marked unavailable
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
'required' modifier must be present on all overrides of a required initializer
required @availability(*, unavailable) convenience init!(coder: NSCoder!) {
有任何想法吗?我的 Xcode 版本是 6.1.1 (6A2008a)。非常感谢。