「Swift」列挙型(enum)を使うサンプル

1.Enumの定義

public enum Student {
    case Name(String)
    case Mark(Int,Int,Int)
}

2.Enumを利用する

var stdDetails = Student.Name("Swift")
var stMarks = Student.Mark(90,88,95)
 
switch stMarks {
case .Name(let studName):
    print("Student Name: \(studName).")
case .Mark(let Mark1, let Mark2, let Mark3):
    print("Student Score: \(Mark1),\(Mark2),\(Mark3)")
}

実行結果
Student Score: 90,88,95

Swift

Posted by arkgame