Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Created August 7, 2015 18:37
Show Gist options
  • Save Ben-G/ce7de1ef00e67523c192 to your computer and use it in GitHub Desktop.
Save Ben-G/ce7de1ef00e67523c192 to your computer and use it in GitHub Desktop.
struct Car: StringLiteralConvertible {
enum CarType: String {
case Mercedes, Porsche, Ford, Unknown
}
var type: CarType
typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
init(unicodeScalarLiteral value: String) {
self.init(carTypeString: value)
}
init(extendedGraphemeClusterLiteral value: String) {
self.init(carTypeString: value)
}
init(stringLiteral value: String) {
self.init(carTypeString: value)
}
init(carTypeString: String) {
let type = CarType(rawValue: carTypeString) ?? .Unknown
self.init(carType: type)
}
init(carType: CarType) {
self.type = carType
}
}
let car: Car = "Mercedes"
print(car.dynamicType)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment