I am trying to build a calculator in swift, but it does not seem to work. I don't really know how to explain it but here is an example: If I sum up 1 + 2 it returns 12 instead of 3.
Here is my code. Please note that num1
is the first part of the operation and num2
the second.
var num1 : String = ""
var num2 : String = ""
@IBOutlet weak var label: UILabel!
@IBAction func button(sender: UIButton) {
var currentnumber = self.label.text
var sendertag = String(sender.tag)
self.label.text = currentnumber! + sendertag
}
@IBAction func sum(sender: UIButton) {
num1 = self.label.text!
self.label.text = ""
}
@IBAction func enter(sender: UIButton) {
num2 = self.label.text!
num1.toInt()
num2.toInt()
self.label.text = num1 + num2
}