Nested Enumerations

suggest change

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents