Reputation: 9940
We have an outlet in swift 4 like this:
@IBOutlet var accured_sum: UITextField!
I declared another variable like this:
var sum: Double?
Now I want to assign Double value of accured_sum to variable sum.
How do I do that?
Upvotes: 1
Views: 805
Reputation: 12051
You can try something like
guard let text = accured_sum.text else { return }
sum = Double(text)
Upvotes: 2
Reputation: 13113
This is another solution, providing a default value
sum = Double(TextField.text ?? "0")
If sum is not nil, it has the double from the TextField. It is is nil: your textfield was not a double OR you never initialized sum.
Upvotes: 0