ios - 如何使用 Firestore 搜索用户?
问题描述
我已经看到这为数据库提供了很多答案,但从未见过 Firestore。我在做这件事时遇到了一些困难。特别是,我似乎无法通过“用户名”对我的集合“用户”中的字段进行排序。我希望能够在我的表格视图中的单元格上显示用户的用户名。我尝试使用 NSDictionary 将用户的“用户名”附加到字典。您可能会说,我对编码很陌生。因此,任何答案都将不胜感激。这是我最近的尝试。我知道这是非常错误的,我只是不知道如何纠正它:
var userArray = [NSDictionary]()
var filteredUsers = [NSDictionary?]()
let db = Firestore.firestore()
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
searchController.searchResultsUpdater = self
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
let userID = Auth.auth().currentUser?.uid
db.collection("users").order(by: "username").getDocuments()
{ (snapshot, error) in
self.userArray.append(snapshot.value as? Dictionary)
self.findUsersTableView.insertRows(at: [IndexPath(row:self.userArray.count-1, section: 0)], with: UITableView.RowAnimation.automatic)
if error != nil {
print(error?.localizedDescription)
}
}
}
解决方案
推荐阅读
- three.js - 三个透明的js后处理方案
- javascript - 将布尔值传递给另一个 Angular 组件
- c++ - 用不同的整数组装 char 数组以模拟日期和时间
- git - 如何解决:未能将一些参考推送到 gitlab?
- python - Pandas: add new column based on category of another column and dictionary
- paypal - 我如何在 paypal api 中更改订阅计划
- postgresql - 对角识别记录并生成主键
- spss-modeler - 自动数字块忽略 SPSS Modeler 中的拆分
- python - Mallet 停止处理大型数据集?
- angular - npm install 不覆盖现有的 node_module 包(自定义更改)