I am working on an app that connects students at my University. Each student will make an account with a variety of profile attributes and as a student, you are able to search other profiles using a filter within the app. So, for example, if I am a freshman interested in joining Big Brothers Big Sisters I can easily search for a "Senior" who is part of "Big Brothers Big Sisters" to ask questions about the organization.
Right now, I am working on the filter and need some help. I am using Swift 4 with a Google Firebase backend. When clicking the search button, after specifying the filter details, I am able to get the filter to work for a single attribute. For example, below I am searching for every user in the database that has a "mateType" (year in school) value of "Senior" (this will later be a variable that pulls the title of the button):
dataRef.reference(withPath: "USERS/").queryOrdered(byChild:"mateType").queryEqual(toValue: "Senior").observeSingleEvent(of: .value, with:
{ snapshot in
var fireAccountArray: [SearchUsers] = []
for fireAccount in snapshot.children {
let fireAccount = SearchUsers(snapshot: fireAccount as! DataSnapshot)
fireAccountArray.append(fireAccount)
}
self.users = fireAccountArray
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.reloadData()
super.viewDidLoad()
})
The issue I am running into is that I want to filter multiple attributes. So, given my earlier example, if I want to find a "Senior" in "Big Brothers Big Sisters", is there a way to filter both of these fields in the search? Can I add another queryEqual() method to the code?
Another question I have is about sorting my search results. I want to sort by firstName, which is an attribute in my database. I got it to sort this way when I didn't have the queryEqual() method:
dataRef.reference(withPath: "USERS/").queryOrdered(byChild:"firstName").observeSingleEvent(of: .value, with:
{ snapshot in
var fireAccountArray: [SearchUsers] = []
for fireAccount in snapshot.children {
let fireAccount = SearchUsers(snapshot: fireAccount as! DataSnapshot)
fireAccountArray.append(fireAccount)
}
self.users = fireAccountArray
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.reloadData()
super.viewDidLoad()
})
Now that I have the queryEqual() method, I need to populate the queryOrdered() method with my child key to get it to work. Is there a way I can order by firstName, but also filter by other child keys?
Thanks in advance for the help! I am really excited about this app and look forward to your responses.