这发生在XCode6-Beta5的一个操场上。
我试图在子类Sprite中向Sprite添加一些功能,但我仍然希望在SKSpriteNode中使用方便的初始化器。但是,我得到以下错误:
"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!)我做错了什么?
发布于 2014-08-20 03:22:06
Swift编程指南中指定的初始化程序链接规则,该指南内容如下:
指定的初始化器必须从它们的直接超类调用指定的初始化器。
如果要在子类实例化中调用超类的方便初始化,则不允许这样做。
希望这有帮助..。:)
发布于 2014-08-20 05:05:36
我不得不摆脱init(coder aDecoder: NSCoder!)方法,这解决了所有的问题。我不知道为什么。
https://stackoverflow.com/questions/25396133
复制相似问题