RapidReverse RapidReverse - 1 year ago 146
iOS Question

How to display variable value in UILabel (Swift)

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


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.

Answer Source


CordLabel.text = "\(CordX), \(CordY)"

In swift, this string formation print the description of any object passed between parenthesis

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download