I've seen this answered quite a lot for Database, but never Firestore. I'm having some difficulty with doing this. In particular, I can't seem to be able to order fields in my collection "users" by "username". I want to be able to display a user's username on a Cell in my Table View. I've tried using NSDictionary to append users' "username" to Dictionary. As you can probably tell, I'm very new to coding. So, any answers would be massively appreciated. This is my latest attempt. I know it's very wrong, I just don't know how to correct it:
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)
}
}
}