Home>

I'm trying to write a code that adds in swift and displays the answer on the label
But for some reason I can't convert String to Int and I don't know how to display it automatically without pressing a button

Can't convert to String with toInt?
What is the automatic display?

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var left: UITextField!
@IBOutlet weak var right: UITextField!
@IBOutlet weak var answ: UILabel!

override func viewDidLoad () {
super.viewDidLoad ()

left.text ="Here"
right.text ="input"

left.delegate = self
right.delegate = self

answ.text ="answer"
self.view.addSubview (answ)

func textFieldDidBeginEditing (_ textField: UITextField) {
print ("textFieldDidBeginEditing: \ (left.text!)")
}

func rightDidBeginEditing (_ textField: UITextField) {
print ("textFieldDidBeginEditing: \ (right.text!)")
}
func textFieldDidEndEditing (_ textField: UITextField) {
print ("textFieldDidEndEditing: \ (left.text!)")
}

func rightFieldDidEndEditing (_ textField: UITextField) {
print ("textFieldDidEndEditing: \ (right.text!)")
}

answ.text = left.text

}

override func didReceiveMemoryWarning () {
super.didReceiveMemoryWarning ()
// Dispose of any resources that can be recreated.
}

}