He continues to tell me: "The GameScene class has no initializers."

import SpriteKit class GameScene: SKScene { var movingGround: JTMovingGround! var hero: JTHero override func didMoveToView(view: SKView) { backgroundColor = UIColor(red: 159.0/255.0, green: 281.0/255.0, blue: 244.0/255.0, alpha: 1.0) movingGround = JTMovingGround(size: CGSizeMake(view.frame.width, 20)) movingGround.position = CGPointMake(0, view.frame.size.height/2) addChild(movingGround) hero = JTHero() hero.position = CGPointMake(70, movingGround.position.y + movingGround.frame.size.height/2 + hero.frame.height/2) addChild(hero) } override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { movingGround.start() } override func update(currentTime: CFTimeInterval) { /* Called before each frame is rendered */ } } 

can someone tell me what went wrong? thanks

+5
source share
2 answers

This is because you have an optional property that does not have a default value.

 var hero: JTHero 

It is not optional, but it also does not matter.

So you can make this optional by doing

 var hero: JTHero? 

Or you can create an init method and set the value there.

Or create a default value ...

 var hero = JTHero() 

There are many ways to do the latter.

+8
source

Classes and structures must set all their stored properties to the appropriate initial value by the time they instantiate this class or structure. Saved properties cannot remain in an undefined state.

You can set the initial value for the saved property in the initializer or assign a default property value as part of the property definition.

Excerpt from: Apple Inc. Fast programming language (Swift 2 Preerelease) iBooks. https://itun.es/us/k5SW7.l

Your GameScene class GameScene not set any initializers for its stored properties and does not define the init() method, and this causes the error you receive.

+1
source

All Articles