Apologies for the elementary question, I'm new to swift and I've been stuck at this for a while but haven't found help.
I'm trying to perform simple math
operations like addition
, multiplication
and division
etc. in my iOS
app but haven't been able to.
When I try to add
two double
numbers (weightField
and heightField
), I get a concatenated string
instead of a sum
.
How do I perform simple math in swift?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var weightField: UITextField!
@IBOutlet weak var heightField: UITextField!
@IBAction func goButton(sender: AnyObject) {
resultField.text = weightField.text + heightField.text
}
@IBOutlet weak var resultField: UILabel!
@IBOutlet weak var commentField: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}