Skip to content

Instantly share code, notes, and snippets.

@yhkaplan
Created February 8, 2019 08:27
Show Gist options
  • Save yhkaplan/b0cfc03b062da1dd7f72723bdbcff479 to your computer and use it in GitHub Desktop.
Save yhkaplan/b0cfc03b062da1dd7f72723bdbcff479 to your computer and use it in GitHub Desktop.
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