Good day, I am studying GKEntities and GKComponent from the book first version I think that has the chapter.
Page 478, Xcode 7 and Swift 2.
Problem:
Xcode: required init?(coder aDecoder: NSCoder) {
fatalError(“init(coder:) has not been implemented”)
}
//Thread 1: Fatal error: init(coder:) has not been implemented
Xcode forces to have this code and it fails every time it is called even using a second custom init().
Questions:
How to avoid using this required init that is everywhere with GKComponents and use normal inits instead to initialize the GKComponent variables.
Note: For all readers of this post I must say my question is not an error on the Book, but help with the complexities of Xcode. But I would appreciate any help.
import SpriteKit
import GameplayKit
class EntityNode : SKSpriteNode {
weak var entity: GKEntity ! //Xcode says there is already a variable with this name.
}
class SpriteComponent : GKComponent {
// A node that gives an entity a visual sprite
let node: EntityNode
init (entity: GKEntity , texture: SKTexture , size: CGSize ) { //I expect this to be called
node = EntityNode (texture: texture,
color: SKColor .whiteColor(), size: size)
node.entity = entity
}
//Xcode forces to use this but fails always.
required init?(coder aDecoder: NSCoder) { //Instead calls this required init
fatalError(“init(coder:) has not been implemented”)
}
//Thread 1: Fatal error: init(coder:) has not been implemented
//It should call instead init (entity: GKEntity , texture: SKTexture , size: CGSize ) that was the one used.
}