mercredi 6 juillet 2016

Swift - enum from string [duplicate]

This question already has an answer here:

how can I get enum (type) for given string? If it was a class I would call NSClassFromString("MyClassName") but what is appropriate function to achive the same with enums?

E.g.:

enum E: String {
    case: One = "-One-"
    case Two = "-Two-"
    case Three = "-Three-"
}

let e = NSClassFromString("E").("-One-") // Lacking function

Thank you in advance.





Aucun commentaire:

Enregistrer un commentaire