//: Playground - noun: a place where people can play import UIKit // 创建一个枚举类型就相当于创建了一个新的数据类型, 所以首字母应该大写 enum GameEnding { case win case lose case draw } var yourScore = 100 var enemyScore = 90 // 初始化枚举变量
// var theGameEnding = GameEnding.win var theGameEnding:GameEnding = .win if yourScore > enemyScore { theGameEnding = GameEnding.win } else if yourScore == enemyScore { theGameEnding = .draw // swift会自动识别到theGameEnding的枚举类型, 所以这里可以省略GameEnding } else if yourScore < enemyScore { theGameEnding = .lose } switch theGameEnding { case .win: print("u win") case .lose: print("u lose") case .draw: print("draw") }