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)
尝试使用以下,
someLabel.text = "\(someVar)"
你可以这样做:
someLabel.text = NSString(format:"%d", someVar)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.