Modifying Anton's answer slightly, you could use:
let text = (textField.text ?? "").isEmpty ? "abc" : textField.text!
(Force-unwrapping the 2nd occurrence of textField.text so text isn't an optional.)
In that case force-unwrapping is safe because the first ?? "nil coalescing operator will have handled the case where textField.text == nil.
If you don't want to use a force-unwrap, break the conversion into 2 lines:
let required = str ?? ""
let text = required.isEmpty ? "abc" : required
Daibaku, the solution you showed in the comments:
guard let text = (textField.text ?? "").isEmpty ? "abc" : textField.text else {
return
}
print(text)
Will return without executing the print statement (or whatever follows the guard) if textField.text == nil