swift 中的初始化程序不会从其超类错误中覆盖设计的初始化程序
Initializer does not override a designed initializer from its superclass error in swift
当我在 Xcode 6.3.2 上打开已经有 swift 类 的项目时,它显示错误。我希望你能帮助我解决这个问题。谢谢。
你这里有几个不同的错误;让我们一次一个地处理它们。
重写便利初始化程序
根据 Apple 的 Swift 文档:
if you write a subclass initializer that matches a superclass convenience initializer, that superclass convenience initializer can never be called directly by your subclass, as per the rules described above in Initializer Delegation for Class Types. Therefore, your subclass is not (strictly speaking) providing an override of the superclass initializer. As a result, you do not write the override modifier when providing a matching implementation of a superclass convenience initializer.
所以放弃 override
关键字,你应该被设置。说到套装……
Swift 1.2
中触摸方法的升级界面
Paul Solt of iphonedev.tv covers this in Swift 1.2 fixes and breaks a few things: you should be excited!,我建议您阅读整个 post(更不用说他链接到的发行说明),但简而言之,NSSet 已被原生 Set 类型取代。正如他所说:
Fix: You'll need to update your method signature (i.e.: the entire first line) to the following:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
他还注意到 Set 上没有 anyObject() 方法,因此您将不得不使用提供的接口来解决这个问题。
希望对您有所帮助!
Swift
You do not need the the override
keyword in a convenience
initializer, because you cannot override such initializer.
修复:删除override
关键字。
convenience init() {
self.init(frame: CGRectZero)
}
此外,init()
是 指定的初始值设定项(在 STBTableViewIndex 中)或者不是。如果是,请将 convenience override init()
替换为 required init()
,这首先意味着 override
。
当我在 Xcode 6.3.2 上打开已经有 swift 类 的项目时,它显示错误。我希望你能帮助我解决这个问题。谢谢。
你这里有几个不同的错误;让我们一次一个地处理它们。
重写便利初始化程序
根据 Apple 的 Swift 文档:
if you write a subclass initializer that matches a superclass convenience initializer, that superclass convenience initializer can never be called directly by your subclass, as per the rules described above in Initializer Delegation for Class Types. Therefore, your subclass is not (strictly speaking) providing an override of the superclass initializer. As a result, you do not write the override modifier when providing a matching implementation of a superclass convenience initializer.
所以放弃 override
关键字,你应该被设置。说到套装……
Swift 1.2
中触摸方法的升级界面
Paul Solt of iphonedev.tv covers this in Swift 1.2 fixes and breaks a few things: you should be excited!,我建议您阅读整个 post(更不用说他链接到的发行说明),但简而言之,NSSet 已被原生 Set 类型取代。正如他所说:
Fix: You'll need to update your method signature (i.e.: the entire first line) to the following:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
他还注意到 Set 上没有 anyObject() 方法,因此您将不得不使用提供的接口来解决这个问题。
希望对您有所帮助!
Swift
You do not need the the
override
keyword in aconvenience
initializer, because you cannot override such initializer.
修复:删除override
关键字。
convenience init() {
self.init(frame: CGRectZero)
}
此外,init()
是 指定的初始值设定项(在 STBTableViewIndex 中)或者不是。如果是,请将 convenience override init()
替换为 required init()
,这首先意味着 override
。