Created
May 5, 2017 11:41
-
-
Save DevAndArtist/c937b7cd9577b3ada8bac7c2a73128c5 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
public enum Foo : OptionSet { | |
case a | |
case b | |
case value(UInt8) | |
public var rawValue: UInt8 { | |
switch self { | |
case .a: | |
return 1 | |
case .b: | |
return 2 | |
case .value(let value): | |
return value | |
} | |
} | |
public init(rawValue: UInt8) { | |
switch rawValue { | |
case 1: | |
self = .a | |
case 2: | |
self = .b | |
default: | |
self = .value(rawValue) | |
} | |
} | |
public static let all: Foo = [.a, .b] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment