Created
August 12, 2016 18:11
-
-
Save ddunbar/71155bfad9fdff6d45c4fcaa29181185 to your computer and use it in GitHub Desktop.
Extensible enum raw values
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 Foundation | |
struct X: Equatable, ExpressibleByStringLiteral { | |
let strings: Set<String> | |
init?(_ characters: String.CharacterView) { | |
let strings = Set<String>(String(characters).components(separatedBy: ",").map{ String($0) }) | |
if strings.isEmpty { | |
return nil | |
} | |
self.strings = strings | |
} | |
init(stringLiteral value: String) { | |
self.init(value.characters)! | |
} | |
init(extendedGraphemeClusterLiteral value: String) { | |
self.init(stringLiteral: value) | |
} | |
init(unicodeScalarLiteral value: String) { | |
self.init(stringLiteral: value) | |
} | |
} | |
func ==(lhs: X, rhs: X) -> Bool { | |
return lhs.strings == rhs.strings | |
} | |
enum E: X { | |
case fooBar = "foo-bar,f" | |
} | |
print(E.fooBar.rawValue) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment