嵌套枚举
你可以将枚举嵌套在另一个内部,这样你就可以构建层次结构的枚举,使其更有条理,更清晰。
enum Orchestra {
enum Strings {
case violin
case viola
case cello
case doubleBasse
}
enum Keyboards {
case piano
case celesta
case harp
}
enum Woodwinds {
case flute
case oboe
case clarinet
case bassoon
case contrabassoon
}
}
你可以像这样使用它:
let instrment1 = Orchestra.Strings.viola
let instrment2 = Orchestra.Keyboards.piano