我正在尝试将UITextfield字符串转换为Integar,然后使用switch语句执行范围检查
已经将文本字段字符串值转换为整数,然后在Switch语句中实现该值
@IBOutlet weak private var load1: UITextField!
@IBOutlet weak private var load2: UITextField!
@IBOutlet weak private var load3: UITextField!
@IBOutlet weak var SS: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
var number1 = String(Int(load1.text!)!)
var number2 = String(Int(load2.text!)!)
var number3 = String(Int(load3.text!)!)
switch number1 {
case 10...33:
print("success")
case 66...77:
print("success")
case 103...109:
print("success")
default:
print("failure")
}
遇到名为“ ClosedRange”类型的表达式模式的错误,无法匹配“ Int?”类型的值。
即使字符串值已经转换为整数,也是如此