Say I have an enum like this:
enum Direction {
case Left
case Right
}
Is there a way to derive a string description of the enum automatically without defining it myself? Something like this:
let direction: Direction = .Left
let description: String = direction.description // should be "Left"
I tried reflect( direction) and the properties on MirrorType but that didn't work.
Not currently. You'll need to implement a description function manually for this. Swift has very limited reflection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With