Created
March 23, 2016 16:06
-
-
Save robnadin/727ecb27274f80c8e923 to your computer and use it in GitHub Desktop.
Ternary operator support for optionals
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
extension Optional: BooleanType { | |
public var boolValue: Bool { | |
switch self { | |
case .Some(let value) where !(value is Bool): | |
return true | |
case .Some(let value as Bool) where value: | |
return true | |
default: | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment