I have an enum that looks like this:
enum IntteruptCause: UInt8 {
case userDisplayDisengage = 0
case userSteeringWheelDisengage = 1
case positionDropout = 2
}
Currently the output from print()
will give me the case name.
I would like to implment CustomStringConvertible
and have it produce both the case name and the rawValue, e.g. the string User_Steering_Wheel_Disengage (1)
.
When I implement var description: String
I have easy access to rawValue
but I cannot seem to find out how to get the enum case name. Normally I would do String(describing: value)
but that would create an infinite recursion if used in description
implementation.
Is it possible to get the enum case name from within the description
implementation?