I am very new to iOS development, but I played with the SpriteKit template app to find out how everything works, and try to boot into Swift while I am in it. The only thing I came across was how to work with subclasses of SpriteKit.
I am in the GameScene.swift file and I am trying to extract a class for the Hello World shortcut, so here is what this file looks like:
// GameScene.swift import SpriteKit class HelloLabel: SKLabelNode { init(fontNamed: String) { super.init(fontNamed: fontNamed) self.text = "Hello, World!" self.fontSize = 65; self.position = CGPoint(x: 400, y: 500); } } class GameScene: SKScene { override func didMoveToView(view: SKView) { /* Setup your scene here */ // let myLabel = SKLabelNode(fontNamed:"Chalkduster") // myLabel.text = "Hello, World!"; // myLabel.fontSize = 65; // myLabel.position = CGPoint(x: 400, y: 500); let myLabel = HelloLabel(fontNamed: "Chalkduster") self.addChild(myLabel) } override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { /* snip, no changes made here */ } override func update(currentTime: CFTimeInterval) { /* snip, no changes made here */ } }
So, HelloLabel is just for going through, to understand how everything gets together, but when I run the application, I get the following error:
/Users/jon/Projects/ErrorExample/ErrorExample/GameScene.swift: 11: 11: fatal error: use of unimplemented initializer 'init()' for class 'ErrorExample.HelloLabel'
I do not understand what this message is trying to tell me. The way I read this error is that it complains that I did not implement an initializer called init in the ErrorExample.HelloLabel class, but it seems to look like I have it!
So what am I doing wrong here - how to extract a class to hide all this setting?
source share