Created
February 7, 2019 17:18
-
-
Save rtauziac/2981473dbc43c4d593645c34e91b6f4d to your computer and use it in GitHub Desktop.
Use optionals with the C# style
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 { | |
var hasValue: Bool { | |
return self != nil | |
} | |
var value: Wrapped { | |
return self! | |
} | |
func value(orDefault defaultValue: Wrapped) -> Wrapped { | |
return self ?? defaultValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment