Swiftのenum(列挙)の宣言
1 2 3 4 5 |
enum Fruits { case Apple case Banana case Orange } |
or
1 |
enum Fruits {Apple, Banana, Orange} |
宣言時に値を代入する場合は
1 2 3 4 5 |
enum Fruits: String { case Apple = "りんご" case Banana = "ばなな" case Orange = "おれんじ" } |
Swiftのenumの呼び出し
1 |
var fruit = Fruits.Banana |
or
1 |
var fruit: Fruits = .Banana |
値を呼び出し(rawValue)
1 |
print(fruit.rawValue) |
参考: SwiftのENUM