Swift 2 - switch语句给我错误

时间:2015-10-24 09:00:51

标签: swift swift2 xcode7 swift2.1

我不知道出了什么问题,但是下面的代码在switch语句中给了我很多错误:

enum GameState {
    case Start
    case Tutorial
    case Play
    case ShowingScore
    case GameOver
}
在GameScene课程中

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        switch GameState {
        case .Start: break
        case .Tutorial: break
        case .Play:
            beginningTouchPosition = location
            tappedForBird = true
            break
        case .ShowingScore: break
        case .GameOver: break
        }
    }

}

我收到的错误消息是:

  1. 类型名称后面的预期成员名称或构造函数调用(这在切换GameState行中)
  2. Enum case&#34; Start&#34;没有找到#34; GameState&#34; (我得到的不仅仅是针对.Start,而是针对每个GameState案例)

1 个答案:

答案 0 :(得分:4)

您正在启用枚举类型GameState 您应该打开一个包含GameState

之一的变量