Converting Values to Enumerations in Swift

From the #swift-lang IRC channel: “Is there any way to go backwards in an enum? I want to look up an enum based on a value.”

Erica Sadun:

The RawRepresentable protocol consists of two underlying functions: toRaw() and fromRaw(). These enable you to transform enumerations to and from underlying data states.