Andrew Andrew - 28 days ago 20
Swift Question

is there exist some alternative of Enum.GetName(Type, Object) method in Swift?

in c# is possible to get enum name of any type with method

Enum.GetName (Type, Object)


is there possible to do the same in Swift?

As example I have some enum that must have Int raw value, but also I need it's own name.
how to do this in Swift 3?

Answer

To get an enumeration case's name as a String, you can use init(describing:) on String:

let s = String(describing: Foo.A) // "A"
Comments