Created
July 3, 2017 07:53
-
-
Save davidkneely/e1d55a2a055c6c702d29ddada045bfde to your computer and use it in GitHub Desktop.
De- "stringifying" a stringly typed enumeration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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