var years = edtYears.text.toInt();
总是抱怨像Value of optional type String? not unwrapped
这样的东西,我试图把?
放进去,但仍然没有运气。任何提示,谢谢
答案 0 :(得分:0)
试试这个:
let years = Int(edtYears.text ?? "0")
答案 1 :(得分:0)
为了让它做同样的事情,我们会这样做:
$(".urls").contents().filter(function() {
return this.nodeType === 3 && this.nodeValue.trim() === toDelete
}).add(this).remove();
答案 2 :(得分:-1)
尝试这样的事情:
var years = String()
override func viewDidLoad() {
super.viewDidLoad()
years = yourTextField.text
print(years)
}
所以这是字符串
现在为Int:
var years = Int()
override func viewDidLoad() {
super.viewDidLoad()
years = Int(yourTextField.text!)
print("\years")
}