Skip to content

Instantly share code, notes, and snippets.

@davidkneely
Created July 3, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidkneely/e1d55a2a055c6c702d29ddada045bfde to your computer and use it in GitHub Desktop.
Save davidkneely/e1d55a2a055c6c702d29ddada045bfde to your computer and use it in GitHub Desktop.
De- "stringifying" a stringly typed enumeration.
import UIKit
struct TrafficLight {
enum TrafficLightState: Int {
case proceed = 1
case proceedWithCaution = 13
case stop = 9
var lightColor: UIColor {
switch self {
case .proceed:
return .green
case .proceedWithCaution:
return .yellow
case .stop:
return .red
}
}
}
var streetName: String
var state: TrafficLightState
}
let firstLight = TrafficLight(streetName: "Main", state: .stop)
print(firstLight.state.rawValue)
print(firstLight.state.lightColor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment