Reputation: 13
So I am currently making an application where there is 4 button. If you press the Up button the variable CordX goes up by 1, if you press the Left button CordY will go down by 1, etc. So I made a UILable to display the cords by using this line
CordLabel.text = CordX + ", " + CordY
But it came with the error
Cannon convert value of type 'Int' to expected argument type 'String' Now
I was expecting the UILabel to change from 0, 0 to -> 1, 0 if I press the Up button. But I couldn't because of the error
I am not yet familiar with Swift but when I was using C I display a value of a variable like this
printf("%d",num1);
The variable in the program was declared with a var and I'm not sure if there is another way to display the variable CordX and CordY.
Upvotes: 0
Views: 3456
Reputation: 1750
You can try this:
CordLabel.text = String(format:"%d , %d", CordX as Int, CordY as Int)
Upvotes: 1
Reputation: 5588
Do
CordLabel.text = "\(CordX), \(CordY)"
In swift, this string formation print the description of any object passed between parenthesis
Upvotes: 2