Last active
August 29, 2015 14:24
-
-
Save danhd123/c1dc8242f48ace176cf8 to your computer and use it in GitHub Desktop.
How to make Strings work in a Uint8 raw value enum.
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
extension UInt8 : StringLiteralConvertible { | |
typealias ExtendedGraphemeClusterLiteralType = String | |
typealias UnicodeScalarLiteralType = String | |
public init(stringLiteral value: StringLiteralType){ | |
self.init(([UInt8]() + value.utf8)[0]) | |
} | |
public init(extendedGraphemeClusterLiteral value: String){ | |
self.init(([UInt8]() + value.utf8)[0]) | |
} | |
public init(unicodeScalarLiteral value: String){ | |
self.init(([UInt8]() + value.utf8)[0]) | |
} | |
} | |
enum Tag : UInt8 { | |
case Byte = "B" // this works now! | |
case Char = "C" | |
case Double = "D" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment