Swift - Must call a designated initializer of the superclass SKSpriteNode error Swift - Must call a designated initializer of the superclass SKSpriteNode error ios ios

Swift - Must call a designated initializer of the superclass SKSpriteNode error


init(texture: SKTexture!, color: UIColor!, size: CGSize) is the only designated initializer in the SKSpriteNode class, the rest are all convenience initializers, so you can't call super on them. Change your code to this:

class Creature: SKSpriteNode {    var isAlive:Bool = false {        didSet {            self.hidden = !isAlive        }    }    var livingNeighbours:Int = 0    init() {        // super.init(imageNamed:"bubble") You can't do this because you are not calling a designated initializer.        let texture = SKTexture(imageNamed: "bubble")        super.init(texture: texture, color: UIColor.clearColor(), size: texture.size())        self.hidden = true    }    init(texture: SKTexture!) {        //super.init(texture: texture) You can't do this because you are not calling a designated initializer.        super.init(texture: texture, color: UIColor.clearColor(), size: texture.size())    }    init(texture: SKTexture!, color: UIColor!, size: CGSize) {        super.init(texture: texture, color: color, size: size)    }}

Furthermore I would consolidate all of these into a single initializer.


Crazy stuff.. I don't fully understand how I managed to fix it.. but this works:

convenience init() {    self.init(imageNamed:"bubble")    self.hidden = true}init(texture: SKTexture!, color: UIColor!, size: CGSize) {    super.init(texture: texture, color: color, size: size)}

add convenience to init and remove init(texture: SKTexture!)