[英]Binary operator '==' cannot be applied to operands of type 'NSObject' and 'String'
I am trying to search users on a UITableView, through a UISearchBar. 我正在尝试通过UISearchBar在UITableView上搜索用户。 The thing is that an error keeps appearing when I try to.
事实是,当我尝试这样做时,错误始终出现。
Here's my code: 这是我的代码:
var isSearching = false
func searchBar(_ searchBar: UISearchBar, textDidChange searchText:String) {
if searchBar.text == nil || searchBar.text == "" {
isSearching = false
view.endEditing(true)
searchTableView.reloadData()
} else {
isSearching = true
filteredUsers = users.filter({$0 == searchBar.text!}) // error appears here
}
searchTableView.reloadData()
}
I am trying to search for the users in my app, through Firebase fetch. 我正在尝试通过Firebase提取在我的应用程序中搜索用户。 I've already fetched the users onto a UITableView, the thing is I cant search for a specific one.
我已经将用户提取到UITableView上,问题是我无法搜索特定的用户。 Please help!
请帮忙! I've tried everything.
我已经尝试了一切。
A type NSObject
can't compared with a type of String
, you need NSObject
类型不能与String
类型进行比较,您需要
filteredUsers = users.filter({$0.someProperty == searchBar.text!})
where someProperty
is a property inside the class 其中
someProperty
是类内的属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.