Guys <3 This is my first project with firebase and I wanna send a quite bunch of data to the database, the problem is when I click the button only the last line of code get send, I also tried to but every row in a function and call them one by one, and the same happens, only the last function work and send it's data, here's the button on click code
@IBAction func Send(_ sender: Any) {
apperfun();
dnamefun();
docfun();
servfun();
pnamefun();
pnumfun();
}
and here's the functions
func apperfun() {
if ap == "1" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Excellent"])}
else if ap == "2" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Good"])}
else if ap == "3" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Bad"])}
}
func dnamefun() {
self.ref.child("fullinfo").child(pname).setValue(["dname":dname])
}
func docfun() {
if doc == "1" {self.ref.child("fullinfo").child(pname).setValue(["level": "Excellent"])}
else if doc == "2" {self.ref.child("fullinfo").child(pname).setValue(["level": "Good"])}
else if doc == "3" {self.ref.child("fullinfo").child(pname).setValue(["level": "Bad"])
self.ref.child("bad").child(pname+phone).setValue(["level": "Bad"])}
}
func servfun() {
if serv == "1" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Excellent"])}
else if serv == "2" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Good"])}
else if serv == "3" {self.ref.child("fullinfo").child(pname).setValue(["performance": "Bad"])}
}
func pnamefun() {
self.ref.child("fullinfo").child(pname).setValue(["pname":pname]);
}
func pnumfun() {
self.ref.child("fullinfo").child(pname).setValue(["pnum":phone]);
}
func receptionfun() {
if recep == "1" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Excellent"])}
else if recep == "2" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Good"])}
else if recep == "3" {self.ref.child("fullinfo").child(pname).setValue(["reception": "Bad"])}
}
setValue will replace any data in that node to your data you are setting. You want to use an update. An update will replace the key if it exists, or add it to your database if it not exists.
You have this:
if ap == "1" {self.ref.child("fullinfo").child(pname).setValue(["apperance": "Excellent"])}
It should be:
if ap == "1" {self.ref.child("fullinfo").child(pname).updateChildValues(["apperance": "Excellent"])}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments