what\'s the easiest way to add the value of two textField
to equal a sum to a label.
Here are the text fields and label I am using:
@IBOutlet we
You can use the power of functional swift like this:
if let textField1String = textField1.text, let textField2String = textField2.text {
let arr = [textField1String, textField2String]
let result = arr.compactMap({ Int($0) }).reduce(0, +) //Cast in Int value + using reduce to sum all the values of array
speedLabel.text = "\(result)"
}