Reputation: 126
I have this code:
DataService.ds.MSGS_DB_REF_KEY1.queryOrdered(byChild: "livelli").observe(.value, with: { snapshot in
for _ in snapshot.children{
if snapshot.hasChild((self.textField.text?.lowercased())!){
DataService.ds.MSGS_DB_REF_LIVELLO1.queryOrdered(byChild: "livello1").observe(.value, with: { (snapshot1) in
self.lvls = []
if let snapshot1 = snapshot1.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshot1 {
if let postDict = snap.value as? [String: AnyObject] {
let level = Levels(levelId: snap.key, levelData: postDict)
self.lvls.append(level)
}
}
}
self.tableView.reloadData()
})
What I would like to do, is to check if the child name, that in my code is equal to the text field, contain one word of string that I write in text field. I have a database that is structured like:
Mydata -> keywords -> keywordlist1 -> name:"level one", value:"level one" (and other strings).
When in text field I write like "I want a random level" I would like to make app recognize the presence of the word "level" in the child name "level one". But with my code, the string is recognized only if it's equal to the name in the data.
Upvotes: 0
Views: 547
Reputation: 7566
There is no way to directly query part of the name of a child. You could download all the children and then search through them in the client, but that's cumbersome at best and not a great option. A better option is to use a Cloud Function to search the database from the back end. Check out this sample and this documentation.
Upvotes: 3