本文翻译自:Converting String to Int with Swift
The application basically calculates acceleration by inputting Initial and final velocity and time and then use a formula to calculate acceleration. 该应用程序基本上通过输入初始和最终速度和时间来计算加速度,然后使用公式来计算加速度。 However, since the values in the text boxes are string, I am unable to convert them to integers. 但是,由于文本框中的值是字符串,我无法将它们转换为整数。
@IBOutlet var txtBox1 : UITextField
@IBOutlet var txtBox2 : UITextField
@IBOutlet var txtBox3 : UITextField
@IBOutlet var lblAnswer : UILabel
@IBAction func btn1(sender : AnyObject) {
let answer1 = "The acceleration is"
var answer2 = txtBox1
var answer3 = txtBox2
var answer4 = txtBox3
#1楼
参考: