我正在尝试让我的UItextField接受浮点数,但目前它只接受一个整数。如何让它接受Swift中的浮点?
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var Swallow13Button: UIButton!
@IBAction func Swallow13Button (sender: AnyObject) {
let a:Int? = data1.text.toInt()
if a > 13.13 {
self.DimensionLabel.text = "Fail Send DWG For Review"
self.view.endEditing(true)
}
else {
self.DimensionLabel.text = "Pass Send DWG for Review"
self.view.endEditing(true)
}
}
答案 0 :(得分:0)
您可以像这样转换为浮动
let a = (data1 as NSString).floatValue
答案 1 :(得分:0)
您可以使用NSString
的{{1}}:
floatValue