Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate enum from Array<String> in Swift?

Here is my enum:

enum myEnum : Int {
    case apple = 0
    case orange
    case lemon
}

I would like to create it from an array. The array elements could be the name of the enums.

let myEnumDictionary : Array<String> = ["apple","orange","lemon"]

So is it possible to create enums from an array?

like image 284
szuniverse Avatar asked Sep 12 '14 14:09

szuniverse


1 Answers

No, it's not possible. In the same way you can't create classes from arrays.

Enums must be compiled. You can't create them dynamically.

like image 50
Sulthan Avatar answered Oct 02 '22 14:10

Sulthan