xcode Swift:覆盖只能在类成员上指定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26828504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift: Override can only be specified on class members
提问by William Clark
In my GameScene.swift file, there are errors that are causing the build to fail.
在我的 GameScene.swift 文件中,存在导致构建失败的错误。
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.
评论部分提到的底部还有一个语法错误。
回答by Shuo
add a "}" before the line
在行前添加“}”
func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
回答by Dordor
there is 2 answers one is that you used override somewhere you can't otherwise your missing a braket or a round braket
有 2 个答案,一个是您在某处使用了覆盖,否则您将错过刹车或圆形刹车