「Swift」関連型enumの使い方

サンプルコード

enum Student{
    case Name(String)
    //型だけ指定
    case Mark(Int,Int,Int)
}
var studDetails = Student.Name("arkgame")
var studMarks = Student.Mark(66,97,69)
switch studMarks {
case .Name(let studName):
    print("student name: \(studName)")
case .Mark(let Mark1, let Mark2, let Mark3):
    print("student score: \(Mark1),\(Mark2),\(Mark3)")
}

実行結果
student score: 66,97,69

Software

Posted by arkgame