我有一个函数收到以下警告:
Value intVal was defined but never used; consider replacing with a boolean test.
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
text = (timerTxtFld.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)
if let intVal = Int(text) {
timerDoneBtn.alpha = 1
timerDoneBtn.enabled = true
} else {
timerDoneBtn.enabled = false
}
return true
}
谁能帮我弄清楚我需要做什么来消除错误?
最佳答案
只需删除 let 并直接对 Int
的结果进行比较。您无缘无故地创建了 intVal
,它提示说这是一个未使用的变量。
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
text = (timerTxtFld.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)
if Int(text) != nil
{
timerDoneBtn.alpha = 1
timerDoneBtn.enabled = true
}
else
{
timerDoneBtn.enabled = false
}
return true
}
关于ios - 警告 : Value was defined but never used; consider replacing with a boolean test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39060215/