ios - Firebase database query for specific selection -


i trying make selection on firebase database on xcode , present results on table, results strange. it's runs loop on same entry. because of table.

  override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "itemcell", for: indexpath) let groceryitem = items[indexpath.row]  // below code query users in firebase check if current user.  let selection = ref.queryordered(bychild: "addedbyuser").queryequal(tovalue : user.email)  selection.observesingleevent(of: .value, with:{ (snapshot: firdatasnapshot) in   if let value = snapshot.value as? [string: any] {     print(value)   } }) //end of code   //if user.email == groceryitem.addedbyuser { cell.textlabel?.text = groceryitem.name  cell.detailtextlabel?.text = groceryitem.addedbyuser // } togglecellcheckbox(cell, iscompleted: groceryitem.completed)  return cell } 

and firebase is:

 {   "expense-items" : {     "20170509" : {       "addedbyuser" : "michael_papado@crymary.gr",       "amount" : 37,       "categorytype" : "shopping",       "completed" : false,       "name" : "dijon",       "paymenttype" : "cash"     },     "zambon" : {       "addedbyuser" : "harry@crymary.gr",       "amount" : 13,       "categorytype" : "shopping",       "completed" : false,       "name" : "zambon",       "paymenttype" : "creditcard"     },     "zouzouni" : {       "addedbyuser" : "harry@crymary.gr",       "amount" : 24,       "categorytype" : "kids",       "completed" : false,       "name" : "zouzouni",       "paymenttype" : "cash"     }   } } 

only 20170509 user logged in , 3 times 20170509 entry. how can count results of selection in order populate table correct results?

so thinking wrong. should not check list on tableview function. had populate new list @ viewdidload , use along.

    if firauth.auth()?.currentuser != nil {   let selection = ref.queryordered(bychild: "addedbyuser").queryequal(tovalue : firauth.auth()?.currentuser?.email)        selection.observesingleevent(of: .value, with:{ (snapshot: firdatasnapshot) in          var newitems: [listitem] = []          item in snapshot.children {           let listitem = listitem(snapshot: item as! firdatasnapshot)           newitems.append(listitem)         }          self.items = newitems          self.tableview.reloaddata()       }) } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -