Created
February 8, 2019 08:27
-
-
Save yhkaplan/b0cfc03b062da1dd7f72723bdbcff479 to your computer and use it in GitHub Desktop.
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
infix operator ??? | |
extension Optional where Wrapped == String { | |
var isEmptyOrNil: Bool { | |
return self == nil || self == "" | |
} | |
static func ???(lhs: String?, rhs: String) -> String { | |
guard let lhs = lhs, lhs != "" else { | |
return rhs | |
} | |
return lhs | |
} | |
static func ???(lhs: String?, rhs: String?) -> String? { | |
guard let lhs = lhs, lhs != "" else { | |
return rhs | |
} | |
return lhs | |
} | |
} | |
let str: String? = nil | |
let newStr = str ??? "Uhoh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment