Accessing a String Enum by index

Swift 4.2 introduced CaseIterable which does exactly the same thing without the need to declare an allValues array. It works like this:

enum MyEnum: String, CaseIterable {
    case foo = "fooString"
    case bar = "barString"
    case baz = "bazString"
}

and you can access its values by

MyEnum.allCases

or a value at a specific index by

MyEnum.allCases[index]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)