Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 如何使用搜索栏从数据库数组中筛选数据_Xcode_Search_Filter - Fatal编程技术网

Xcode 如何使用搜索栏从数据库数组中筛选数据

Xcode 如何使用搜索栏从数据库数组中筛选数据,xcode,search,filter,Xcode,Search,Filter,Im使用搜索栏过滤数据库中的数据,并填充tableView。我在搜索部分出错了 Value of type 'DataSnapshot' has no member 'contains' 这是密码 func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { if searchBar.text == nil || searchBar.text == "" { isSearchin

Im使用搜索栏过滤数据库中的数据,并填充tableView。我在搜索部分出错了

Value of type 'DataSnapshot' has no member 'contains'
这是密码

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    if searchBar.text == nil || searchBar.text == "" {
        isSearching = false
        view.endEditing(true)
        tableView.reloadData()
    } else {
        isSearching = true
        filteredColorRequests = colors.filter{$0.contains(searchBar.text!)}
        tableView.reloadData()
    }
}

如何

您当然希望搜索特定的
字符串
属性,例如
名称

使用
searchText
参数,而不是从搜索栏获取搜索字符串,该参数已经是非可选的

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    if searchText.isEmpty {
        isSearching = false
        view.endEditing(true)
    } else {
        isSearching = true
        filteredColorRequests = colors.filter{(($0.value as! [String:Any])["name"] as! String).contains(searchText)}
    }
    tableView.reloadData()
}

你好,瓦迪亚人。当我尝试键入某个内容时,它不会显示任何内容。我已经更新了cellForRowAt
名称
只是一个占位符。我不知道快照包含什么。它在@vadian工作。谢谢我还有一个问题。您使用什么代码过滤与当前用户的距离。就像我想在名单上显示最接近最远的人一样。我有一个经度和纬度的即时快照。使用
CoreLocation
的API。从lat/long创建
CLLocation
对象并计算两个位置之间的距离很容易。将
.contains(searchText)
替换为
。范围(of:searchText,选项:。不区分大小写)!=无