I am setting a variable to the doubleValue
of a UITextField
with the following,
let enteredTargetDays : Double = numberFormatter.number(from: textField2.text!)?.doubleValue ?? 0.00
This ensures that even if the textField2.text
is nil
and a doubleValue
cannot be extrapolated, 0.00
will return. But what if I don't want a default value, and just want the function to return if the textField2.text
is nil?
Is the only way to do this to first check textField2.text
for nil
before setting the variable, or is there is a quicker, one-liner, Swifty way to do it?