William Clark
William Clark

Reputation: 91

Swift: Override can only be specified on class members

In my GameScene.swift file, there are errors that are causing the build to fail.

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        let sprite = SKSpriteNode(imageNamed:"Spaceship")

        sprite.xScale = 0.5
        sprite.yScale = 0.5
        sprite.position = location

        let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)

        sprite.runAction(SKAction.repeatActionForever(action))

        self.addChild(sprite)
    }
}

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}

I am told that 'override can only be specified on class members'.

How should I fix this?

This is the whole thing:

//
//  GameScene.swift
//  Swipe Racer
//
//  Created by William Clark on 25/10/2014.
//  Copyright (c) 2014 Arc of Clark. All rights reserved.
//

import SpriteKit
import Darwin

class GameScene: SKScene {

override func didMoveToView(view: SKView) {
    /* Setup your scene here */

    var swipes = SPSwipes()

    if swipes.no_of_swipes == 5 {
        var array = Array<UInt32>(count: 5, repeatedValue: 0)
        for i in 0 ..< 5 {
            array[i] = arc4random_uniform(100)}
        }

    if swipes.no_of_swipes == 10 {
        var array = Array<UInt32>(count: 10, repeatedValue: 0)
        for i in 0 ..< 10 {
            array[i] = arc4random_uniform(100)}
    }

    if swipes.no_of_swipes == 25 {
        var array = Array<UInt32>(count: 25, repeatedValue: 0)
        for i in 0 ..< 25 {
            array[i] = arc4random_uniform(100)}
    }

 func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        let sprite = SKSpriteNode(imageNamed:"Spaceship")

        sprite.xScale = 0.5
        sprite.yScale = 0.5
        sprite.position = location

        let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)

        sprite.runAction(SKAction.repeatActionForever(action))

        self.addChild(sprite)
    }
}

func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}
}

There is also a syntax error at the bottom mentioned in the comment section.

Upvotes: 0

Views: 12119

Answers (2)

Dordor
Dordor

Reputation: 179

there is 2 answers one is that you used override somewhere you can't otherwise your missing a braket or a round braket

Upvotes: 1

Shuo
Shuo

Reputation: 8937

add a "}" before the line

func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

Upvotes: 12

Related Questions