Created
May 1, 2019 15:07
-
-
Save koingdev/8c6e3f760f80877020fc3fdebebf6def to your computer and use it in GitHub Desktop.
Optional extension
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 where Wrapped == String { | |
var orEmpty: Wrapped { | |
return self ?? "" | |
} | |
var isNullOrEmpty: Bool { | |
return self?.isEmpty ?? true | |
} | |
} | |
extension Optional where Wrapped == Bool { | |
var orTrue: Wrapped { | |
return self ?? true | |
} | |
var orFalse: Wrapped { | |
return self ?? false | |
} | |
} | |
extension Optional { | |
func or(_ other: @autoclosure () -> Wrapped?) -> Wrapped? { | |
return self ?? other() ?? nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment