Just use the attribute text UITextFieldto get the value (which is a string).
Then use a method toInt()(which returns optional) to convert it to Integer so you can perform math operations.
@IBOutlet weak var field: UITextField!
@IBOutlet weak var label: UILabel!
@IBAction func getVal () {
var text: String = field.text
var multipliedNum: Int = 0
if let num = text.toInt() {
multipliedNum = num * 10
}
label.text = "\(multipliedNum)"
}
source
share