枚举的基本用法 Enumerations

前端之家收集整理的这篇文章主要介绍了枚举的基本用法 Enumerations前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
枚举的基本用法 Enumerations
Enumeration
enum SomeEnumeration{
case enumeration1
case enumeration2
case enumeration3
...
}


import UIKit


enum GameEnding{
case Win
case Lose
case Draw
}
var yourscore:Int = 80
var enemyscore:Int = 90


var theGameEnding:GameEnding
if yourDcore>enemyscore{ theGameEnding = GameEnding.Win}
else if yourscore == enemyscore{theGameEnding = .Draw}
else { theGameEnding = .Lose}


switch theGameEnding
{
case.Win:println("You Win")
case.Lose:println("You Lose")
case.Drawn:println("It is a draw")


}


猜你在找的Swift相关文章