Skip to content

Instantly share code, notes, and snippets.

@JensAyton
Created February 25, 2021 09:02
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 JensAyton/92167cdbff1dfd7efd9e6c16be533241 to your computer and use it in GitHub Desktop.
Save JensAyton/92167cdbff1dfd7efd9e6c16be533241 to your computer and use it in GitHub Desktop.
A very useful type
enum Tristate: ExpressibleByNilLiteral, ExpressibleByBooleanLiteral {
case maybe
case no
case yes
init(nilLiteral: Void) {
self = .maybe
}
init(booleanLiteral value: Bool) {
self = value ? .yes : .no
}
}
let a: Tristate = nil // .maybe
let b: Tristate = false // .no
let c: Tristate = true // .yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment