今天练习代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var op1: UITextField!
@IBOutlet weak var op2: UITextField!
@IBOutlet weak var result: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func add(sender: AnyObject) {
let _op1 = Int(op1.text!)
let _op2 = Int(op2.text!)
let resultValue = _op1! + _op2!
result.text = String(resultValue)
}
}
学到的东西:
toInt() 已经过时,现在的话,需要使用Int(String) 转换
var 与 let 的区别
为什么用var 会有警告,不是很清楚,求大神指点