Adding data to a specific UID in firebase

試著忘記壹切 提交于 2019-12-23 03:32:25

问题


i've been trying to store user inputted data to the their personal uid in firebase but so far i've only been able to do this when the user created an account and what im trying to find out is how to store data from a text field in xcode to the firebase realtime database under a unique uid, that the user gets when they create an account??

for example: i have 3 textfields that will store the user information to the already assigned UID when they created the account at the start of the application.

let uid = user.uid
ref.child("users").child(user!.uid).setValue(["DOB": self.DOB. text!,
"Address": self.address.text!, "age":self.age.text!])

回答1:


I've managed to solve the problem, assuming the user is already authenticated within the application: create an IBoutlet for the textfield named "yourtextfieldname" convert the textfield data into an NSSTRING and place the otherstr variable in the setValue parameter. then add the function to the button action.

   let userID = FIRAuth.auth()?.currentUser?.uid
   //gets current user uid

   func test() {

    let str = yourtextfieldname.text
    let otherstr = str! as NSString
   //convert textfield datatype NSString

    self.ref.child("users").child(userID!).child("yourtextfieldname").setValue(otherstr)

}

@IBAction func but(sender: AnyObject) {
    //calling test function
  updateProfile()


}

Json data structure

{
 "users": {
     "unique UID": {
         "test": "strTest"

               }
            }
 }


来源:https://stackoverflow.com/questions/38742782/adding-data-to-a-specific-uid-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!