I have a dictionary that I am trying to append information to but instead of appending to it just deletes the previous information. The dictionaries are in two different scopes. The dictionary name is personal info. They are on line 40 and 47. I tried doing personalInfo.append but it tells me that it has no member append. I am trying to save information to a database from to different views. This is the code that I have right now:
@IBAction func sendPhoneAuthCode(_ sender: Any){
if let phoneNum = phoneNumber.text { // No more need to unwrap phoneNum later
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNum, uiDelegate: nil) { (verificationID, error) in
// Sign in using the verificationID and the code sent to the user
// …
// if phoneNum == nil {
if error != nil {
print("verifyPhoneNumber went NOT OK")
// REPLACE BY print self.present(alert, animated: true, completion: nil)
DispatchQueue.global(qos: .userInitiated).async {
let titre = " Missing Information "
let detailMsg = "Please enter your phone number"
let controller = UIAlertController(title: titre, message: detailMsg, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel)
controller.addAction(okAction)
DispatchQueue.main.async {
self.present(controller, animated: true, completion: nil)
}
}
return
} else {
print("verifyPhoneNumber went OK")
// You have to test credential here, where do you do this ?
}
}
} else {
print("phoneNumber.text is nil")
return
}
personalInfo = ["Phone Number" : phoneNumber.text]
print("Setting userDefaults", verificationID)
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
}
@IBAction func savePersonalInfo(_ sender: Any) {
personalInfo = ["First Name" : firstName.text, "Last Name" : lastName.text, "Email" : email.text, "Address Line 1" : addressLine1.text, "Address Line 2" : addressLine2.text]
let ref = Database.database().reference()
ref.childByAutoId().setValue(personalInfo)
}