Ios 将项目从Swift 2.3转换为Swift 3.0-二进制运算符'==';无法应用于类型为';UITextField';和';布尔';
我有一个在Swift 2.3上运行的项目,没有错误。我已将此项目更新为Swift 3.0,解决了所有问题,但没有解决此问题: 错误消息如下:二进制运算符“==”不能应用于“UITextField”和“Bool”类型的操作数。Ios 将项目从Swift 2.3转换为Swift 3.0-二进制运算符'==';无法应用于类型为';UITextField';和';布尔';,ios,swift,xcode,Ios,Swift,Xcode,我有一个在Swift 2.3上运行的项目,没有错误。我已将此项目更新为Swift 3.0,解决了所有问题,但没有解决此问题: 错误消息如下:二进制运算符“==”不能应用于“UITextField”和“Bool”类型的操作数。 func textFieldShouldClear(_ textField: UITextField) -> Bool { // called when clear button pressed. return NO to ignore (no notific
func textFieldShouldClear(_ textField: UITextField) -> Bool {
// called when clear button pressed. return NO to ignore (no notifications)
if textField == true {
tableView.reloadData()
}
return true
}
我试图在这里找到一个解决方案,但没有涉及swift 3.0。
有人知道吗
谢谢你
Olli您正在将
UITextField
与Bool
进行比较,这是不可能的,因为您可以使用=
运算符仅比较相同类型的对象
只需删除if
子句:
func textFieldShouldClear(_ textField: UITextField) -> Bool {
tableView.reloadData()
return true
}
也许您正在尝试查看textfield是否为空。您可以通过以下方式实现:
func textFieldShouldClear(_ textField: UITextField) -> Bool {
// called when clear button pressed. return NO to ignore (no notifications)
if textField.hasText {
tableView.reloadData()
}
return true
}
如果textField==true,您想用
在语义上表达什么?错误很明显,您无法将UITextField与Bool类型进行比较,这没有任何意义。我不知道这段代码应该做什么,你不想检查它传递的文本字段是你在你的财产某处存储的特定字段吗?谢谢大家的评论,这让我走上了正确的道路。最终得到了与Shallowthough建议的相同的解决方案。