Swift Language Enums Nested Enumerations


You can nest enumerations one inside an other, this allows you to structure hierarchical enums to be more organized and clear.

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

And you can use it like that:

let instrment1 = Orchestra.Strings.viola
let instrment2 = Orchestra.Keyboards.piano