How do I update a UILabel which calculates the total of two amounts and prints the answer on the label?
I have $50 and want to add $50 to the total on the label every time the button is pressed.
One of the amounts would be the total that is already printed on the label from the first click of the button. So I want to click the button again and it to add the 50 each time I click.
I'm using the latest versions of xcode and swift.
The button and label are connected and tested by printing to console.
func totalMoneyUpdate() {
totalMoney.text = "$50.00"
// this gives me $50 on the label but don't add it each time i hit the button.
// I have tried to change the label to a Int but have fail.
totalMoney:Int = $50.00
//and tried totalMoney:Int + $50.00
//I tried
var a = 25
var b = 25
let totalMoney.text = (a + b) // this only prints $50 to the label once.
//I tried
totalMoney.text = "50.00"
var a = (totalMoney.text as! NSString).floatValue
var b = (totalMoney.text as! NSString).floatValue
var sum = a + b
totalMoney.text = "\(sum)"
// this prints 100 to the label but don't do anything next time I press.
}
I think I somehow need to update the label each time button is pressed.
I expect the output to add 50 to the total every time I click the button and display the total on the label.