Swift - 添加两个字符串数字

时间:2015-10-09 15:39:26

标签: swift

用户基本上输入数字并点击按钮。然后将其添加到标签的值之上。但是,以下代码将其添加到字符串的末尾,并且不会物理添加字符串

let currentStamps = Int(labelStamps.text!)
let stamps = Int(textFieldStamps.text!)
labelStamps.text = stamps! + currentStamps!

请帮助

1 个答案:

答案 0 :(得分:0)

试试这个:

    if let currentStamps = Int(labelStamps.text!), let stamps = Int(textFieldStamps.text!) {
        labelStamps.text = "\(stamps + currentStamps)"
    }