【问题标题】:How do I associate my value with its key when writing to Firebase in Swift 3?在 Swift 3 中写入 Firebase 时,如何将我的值与其键相关联?
【发布时间】:2017-01-29 04:32:32
【问题描述】:

我正在使用 SwiftFirebase 将配置文件信息写入我的 FireBase 数据库。

FIRAuth.auth()?.signIn(withEmail: userEmail!, password: userPassword!) { (user, error) in

                    self.ref = FIRDatabase.database().reference()


                    self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).setValue(String(describing: user))
                    self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).child("User Email").setValue([userEmail])

我希望数据库读取为:

UID

---UserFirstName: "在此处插入姓名"

但是我得到了:

UID

---用户名

--------0: "在此处插入名称"

我知道我只是在这里缺少一些基本的东西。这是我第一次接触 Swift。我读过的任何其他内容似乎都没有提到这个问题。我确定我只是没有在代码的语法中正确地表示“键值”关系。

【问题讨论】:

    标签: json swift firebase key-value


    【解决方案1】:

    我通过将代码更改为如下所示来修复它:

    self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).updateChildValues(["User Email": userEmail!])
    

    updateChildValues 的更改允许我每次都不会在节点下覆盖自己,(["User Email": userEmail!]) 片段允许我将值直接归因于键。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多