ios - 使用三个键 Swift 5 过滤 Firebase QueryDocumentSnapshot 数组
问题描述
我已经对一个简单的数组应用了过滤器,但现在数据在QueryDocumentSnapshot
数组中我无法过滤它,它应该用 3 个键过滤phone
,,name
email
extension CleanerListViewController: UISearchBarDelegate{
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchText.isEmpty{
filterList = self.cleaner
}else{
let keys = ["name", "phone", "email"]
let subPredicates = keys.map({ NSPredicate(format: "%K CONTAINS[c] %@", $0, searchText) })
let predicate = NSCompoundPredicate(orPredicateWithSubpredicates: subPredicates)
// cleaner is of type [QueryDocumentSnapshot]!
filterList = cleaner.filter { predicate.evaluate(with: $0) }
}
self.tblCleanerList.reloadData()
}
}
我已经尝试过.filter
一系列[QueryDocumentSnapshot]
但无法弄清楚该怎么做
它会导致崩溃
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FIRQueryDocumentSnapshot 0x600002b00580> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.'
解决方案
推荐阅读
- rest - 如何使用支持 Rest 和 GraphQL 的 light-4j 构建应用程序
- amazon-cloudfront - 缓存与无缓存是否会影响 CloudFront 定价?
- typescript - TypeScript:让库的用户定义类型
- mysql - MySQL SELECT * 在 Unicode 上失败
- node.js - node.js 和 express 的区别
- python - 通过单击页面中的每个超链接来抓取网站
- r - 在 R 中满足另一个条件时(即当另一个变量是特定值时)需要帮助用 NA 替换值
- javascript - props.images.map 不是函数(函数组件)
- entity-framework - 在 EF Core 中的每条记录上自动设置创建和修改日期的问题
- java - Spring将实例化委托给另一个线程