Reputation: 273
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.
Upvotes: 8
Views: 35910
Reputation: 137
you can do something like this:
someLabel.text = NSString(format:"%d", someVar)
Upvotes: 4
Reputation: 7789
Try this
someLabel.text = "\(someVar)"
Yeah
someLabel.text = String(someVar)
Go through this doc https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html
Upvotes: 3
Reputation: 130193
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)
Upvotes: 32