Created
February 18, 2017 19:26
-
-
Save wh1pch81n/8450d607773adb185bbf128eeb46ce19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
enum Planets: String { | |
case Mercury | |
case Venus | |
case Earth | |
} | |
// Add protocol to enums that need it | |
public protocol UsesRawValue { | |
var rawValue: String { get } | |
} | |
extension Planets: UsesRawValue {} | |
extension Dictionary where Key: ExpressibleByStringLiteral { | |
subscript(key: UsesRawValue) -> Value? { | |
get { return self[key.rawValue as! Key] } | |
set { self[key.rawValue as! Key] = newValue } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment