Created
August 7, 2015 18:37
-
-
Save Ben-G/ce7de1ef00e67523c192 to your computer and use it in GitHub Desktop.
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
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