ios - 如何在 Swift 和 Firebase 中更新数据而不影响现有数据?

标签 ios swift firebase firebase-realtime-database

因此,在我的应用程序中,用户将数据输入到已保存并存储在我的 firebase 数据库中的文本字段中。但是当输入改变时,它完全覆盖了我之前在数据库中的内容。

这是代码;

    @IBAction func cont(_ sender: UIButton) {
    // Database reference
    ref = Database.database().reference()

    //Referencing the actual table the data is updated and stored in
    let customerRef = ref.child("customerDetails")
    customerRef.updateChildValues(["email": emailTextField.text!])
    customerRef.updateChildValues(["firstName" : firstNTextField.text!])

}

这是我的数据库的图像;

enter image description here

将收集多个数据,我将添加更多字段,例如姓氏和其他内容。那么现有数据如何才能不受影响呢?

最佳答案

使用此功能,您可以将列表添加到数据库的 customerDetails 内部,而不会影响任何现有数据。另外,您可以像这样在一行中更新您的值:

let ref = Database.database().reference()
let customerRef = ref.child("customerDetails").childByAutoId()
customerRef.updateChildValues(["email": emailTextField.text!,
                               "firstName": firstNTextField.text!])

关于ios - 如何在 Swift 和 Firebase 中更新数据而不影响现有数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49260381/

相关文章:

swift - 在 Ubuntu 上使用 Swift 构建静态链接的可执行文件

ios - 以编程方式更新通过 Inspector 设置的 Autolayout Constraints

firebase - PluginRegistry无法转换为FlutterEngine

firebase - 配置类似反向代理的 Firebase 托管解决方案

javascript - Electron:Firebase 和 Facebook 身份验证?

iphone - UITableViewCell 在编辑模式下移动时显示两个不同的项目

ios - 在 ParentViewController 中检测 ChildViewController 的 Pop

ios - 如何在 ViewController 中显示弹出窗口

ios - 查找嵌套 UIStackView 中 TextField 的绝对来源

ios - CFBundleURLIconFile key 在 iOS 中是否有任何用途?