How can I create a user with multiple attributes in Firebase with Swift?

后端 未结 2 594
深忆病人
深忆病人 2021-01-06 17:38

I am so new to Firebase (a couple of hours only) and still trying to absorb most of its concepts. I followed the documentation but still found no direct answer to my questio

2条回答
  •  旧巷少年郎
    2021-01-06 18:08

    I am assuming that since you will be having multiple users, you will have them authenticated before they access your app. You may first create a Struct file in Swift, as follows:

    import Foundation
    import Firebase
    
    struct User {
    let uid: String
    let email: String
    let usermobilenumber : String
    let userFirstName: String
    let userLastName : String
    
    // Initialize from Firebase
    init(authData: FAuthData) {
        uid = authData.uid
        email = authData.providerData["email"] as! String
        userhandle = authData.providerData["userhandle"] as! String
        userFirstName = authData.providerData["userFirstName"] as! String
        userLastName = authData.providerData["userLastName"] as! String
    }
    
    // Initialize from arbitrary data
    init(uid: String, email: String, userLastName: String, userFirstName: String, usermobilenumber: String) {
        self.uid = uid
        self.email = email
        self.userLastName = userLastName
        self.userFirstName = userFirstName
        self.usermobilenumber = userhandle
    
    }
    }
    

    Using textfields, perform the user input task. Then, you need to access the Firebase node where you want to write the data (which you may have previously saved as ref = Firebase(url: "my-awesome-app.firebaseio.com/userinfo"), and simply ref.updateChildValues().

    My answer is a schematic response to help you get started, because Firebase documentation is quite exhaustive and has answers to most of the questions that a beginner encounters. You should read this website, and go through the API References to help you completely achieve what you want.

提交回复
热议问题