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.
(String)someVar
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)
Try using the following,
someLabel.text = "\(someVar)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With