Skip to content

Instantly share code, notes, and snippets.

@dimpiax
Created July 17, 2017 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimpiax/a7ad78c11804ca30a06b1a856632a070 to your computer and use it in GitHub Desktop.
Save dimpiax/a7ad78c11804ca30a06b1a856632a070 to your computer and use it in GitHub Desktop.
Optional Bool shortcut
extension Optional where Wrapped == Bool {
var bool: Bool {
switch self {
case .some(let value): return value == true
case .none: return false
}
}
}
var foo: Bool? = true
if foo.bool {
print("Hello!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment