【发布时间】:2015-03-25 03:26:19
【问题描述】:
我有一个带有标签和 UIAction 按钮的 Xcode 项目。点击按钮后,我希望标签中显示的值增加 1。问题是我无法在标签中显示变量“值”,因为它是一个整数,并且标签采用字符串数据类型。这是我到目前为止的代码:
var value = 0
@IBOutlet var label: UILabel!
@IBAction func button(sender: AnyObject) {
value = value + 1
label.text = value
}
【问题讨论】:
-
value.description 或字符串插值“\(value)”
标签: string swift casting integer int