uitableview - Update values stored in random generated keys in Firebase - Swift -


currently trying update many values of alarms such label, time, repeateddays, etc. in app, once user creates alarm displayed in tableview. once click alarm on tableview, should able edit values. of works in ui part, in firebase when save edits have done alarm, new alarm object created. values alarm updated once edited(and saved), instead of adding new alarm.

below structure in firebase of app:

enter image description here

here snippet of code show have tried do:

override func prepare(for segue: uistoryboardsegue, sender: any?) {         if segue.identifier == "save" {              var alarmrefkey = alarmref.key //the unique alarm key              let displayalarms = segue.destination as! displayalarms //unwind segue destination              if alarm != nil {//alarm object, if there alarm, can edit                 print("there alarm.")                 let timeformatter = dateformatter()                 timeformatter.timestyle = dateformatter.style.short                  timepicker.addtarget(self, action: selector(("handler:")), for: uicontrolevents.valuechanged)                  let strdate: string? = timeformatter.string(from: timepicker.date)                 print("\(strdate!) time!")                 alarm?.time = strdate!                 alarm?.alarmlabel = updatelabeltext.text ?? ""                  self.tableview.reloaddata()                  let key = alarmrefkey                  print("\(key) alarm key")                 var ref: databasereference                 ref = database.database().reference()                 let currentuserid = auth.auth().currentuser?.uid//current user's id   //                let parameters: any? = ["alarmlabel": updatelabeltext.text!, "alarmtime": strdate!, "userid": currentuserid!, "repeateddays": weekdaysselected]                  //where having trouble.                 //updating values in alarm associated key.                 ref.child("alarms").child(key).updatechildvalues(["alarmlabel": updatelabeltext.text!, "alarmtime": strdate!, "userid": currentuserid!, "repeateddays": weekdaysselected])              } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -