在 Swift 3 中写入 Firebase 时如何将我的值与其键相关联?
How do I associate my value with its key when writing to Firebase in Swift 3?
我正在与 Swift
和 Firebase
合作,将配置文件信息写入我的 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: "Insert Name Here"
但我得到的是:
UID
---UserFirstName
------0: "Insert Name Here"
我知道我只是缺少一些基本的东西。这是我在 Swift 的第一次拍摄。我读过的任何其他内容似乎都没有提到这个问题。我确定我只是没有在代码语法中正确表示 "key-value" 关系。
我通过修改我的代码来修复它,如下所示:
self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).updateChildValues(["User Email": userEmail!])
改成updateChildValues
让我不用每次都在节点下覆盖自己,(["User Email": userEmail!])
这块让我直接把值归于键。
我正在与 Swift
和 Firebase
合作,将配置文件信息写入我的 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: "Insert Name Here"
但我得到的是:
UID
---UserFirstName
------0: "Insert Name Here"
我知道我只是缺少一些基本的东西。这是我在 Swift 的第一次拍摄。我读过的任何其他内容似乎都没有提到这个问题。我确定我只是没有在代码语法中正确表示 "key-value" 关系。
我通过修改我的代码来修复它,如下所示:
self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).updateChildValues(["User Email": userEmail!])
改成updateChildValues
让我不用每次都在节点下覆盖自己,(["User Email": userEmail!])
这块让我直接把值归于键。