这发生在XCode6-Beta5的一个操场上
我试图在一个子类SKSpriteNode中添加一些功能,但是我仍然想使用Sprite中的方便初始化器。但是,我得到以下错误:

"Cannot convert the expression's type 'Sprite' to type 'Sprite'"

从这个代码:
import Cocoa
import SpriteKit

class Sprite : SKSpriteNode {
    // The following code makes this not compile
    // required init(coder aDecoder: NSCoder!) {
    //     super.init(coder: aDecoder)
    // }
}

var sprite = Sprite(imageNamed: "Rayman1.png") // Error occurs on this line

所讨论的方便初始值设定项声明如下:
convenience init(imageNamed name: String!)

我做错什么了?

最佳答案

Swift编程指南中指定的初始化器链接规则,内容如下:
指定的初始值设定项必须从其直接超类调用指定的初始值设定项。
如果在子类实例化中调用超类的便利初始化,则这是不允许的。
希望这有帮助。。:)

10-07 19:05
查看更多