Skip to content

Instantly share code, notes, and snippets.

@DevAndArtist
Created May 5, 2017 11:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevAndArtist/c937b7cd9577b3ada8bac7c2a73128c5 to your computer and use it in GitHub Desktop.
Save DevAndArtist/c937b7cd9577b3ada8bac7c2a73128c5 to your computer and use it in GitHub Desktop.
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