Changerrs Changerrs - 5 months ago 30
Swift Question

How to display Int to screen/label SWIFT

I am not sure how to display an int to the screen?

this is what i've tried:

@IBOutlet weak var Button: UIButton!
@IBOutlet weak var someLabel: UILabel!
var someVar = 0

@IBAction func buttonPressed(sender: AnyObject) {
someVar = someVar + 1
someLabel.text = (String)someVar

I have linked up the button and label to the view controller.

Thanks, sorry for the noob question.


This is not a valid type cast in Swift.


If String was a valid subtype of Int, you could downcast with the "as" operator, but it isn't.

In this case, you want to initialize a new String passing the Int as an argument.

someLabel.text = String(someVar)