Created
July 17, 2017 09:05
-
-
Save dimpiax/a7ad78c11804ca30a06b1a856632a070 to your computer and use it in GitHub Desktop.
Optional Bool shortcut
This file contains hidden or 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
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