简体   繁体   English

如何使用Swift在Firebase中创建具有多个属性的用户?

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

I am so new to Firebase (a couple of hours only) and still trying to absorb most of its concepts. 我是Firebase的新手(仅限几个小时),仍然试图吸收其大部分概念。 I followed the documentation but still found no direct answer to my question. 我按照文档,但仍然没有找到我的问题的直接答案。 I have a registration form in my app...it takes username, name, mobile, etc. I used the firebase createUser function but that only creates a user with email and password. 我在我的应用程序中有一个注册表单...它需要用户名,名称,移动设备等。我使用了firebase createUser函数,但只创建了一个带有电子邮件和密码的用户。

How can I create a user with multiple attributes (name, mobile, username, etc)? 如何创建具有多个属性(名称,移动设备,用户名等)的用户? Later on, I would like to query a username and get all associated attributes with them so to do that I need to have the attributes. 稍后,我想查询用户名并获取所有相关属性,这样做我需要拥有属性。

PS coming from Parse, this is not as straightforward. PS来自Parse,这不是那么简单。

Traditionally, you would create a /users node in Firebase that contains any other info you want to store about that user. 传统上,您将在Firebase中创建一个/ users节点,其中包含您要存储的有关该用户的任何其他信息。

Use the uid (user_id) as the node name for each user. 使用uid(user_id)作为每个用户的节点名称。

users
  uid_0
   name: "Bill"
   food: "Pizza"
  uid_1
   name: "Ted"
   food: "Tacos"

This question has been asked before so please try searching for questions similar to yours before asking. 之前已经提出过这个问题,所以请在尝试之前尝试搜索与您类似的问题。

A bit more info here Firebase Users Node 有关Firebase用户节点的更多信息

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: 您可以先在Swift中创建一个Struct文件,如下所示:

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() . 然后,您需要访问要在其中写入数据的Firebase节点(您之前可能已将其保存为ref = Firebase(url: "my-awesome-app.firebaseio.com/userinfo") ,只需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. 我的答案是帮助您入门的示意图,因为Firebase文档非常详尽,并且可以解答初学者遇到的大多数问题。 You should read this website , and go through the API References to help you completely achieve what you want. 您应该阅读本网站 ,并阅读API参考资料,以帮助您完全实现您的目标。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Swift在Firebase中更新用户的分数? - How can I update user's score in Firebase using Swift? 如何快速从Firebase中为用户获取特定数据? - how can i get a specific data for a user from firebase in swift? 我如何基于用户输入快速创建UITextField - how can i create UITextField based on a user input in swift 如何在Swift 4中通过SwiftyJson和Almofire创建多个按钮? - How can I create multiple button by SwiftyJson and Almofire in swift 4? 如何限制我在 iOS(swift)/Firebase 应用程序上为每个用户提供的存储空间? - How can I limit the storage I give each user on an iOS(swift)/Firebase app? 用户使用Firebase Auth和Swift验证电子邮件后,如何重定向回我的应用程序? - How can I redirect back to my app after the user has verified their email using Firebase Auth and Swift? Swift Firebase-如何验证`PhoneAuthCredential`并保持用户当前使用其当前电子邮件uid登录 - Swift Firebase -How can I verify the `PhoneAuthCredential` and keep the user currently signed in with their current email uid 使用Swift和Firebase,如何从经过身份验证的应用程序用户向自己发送自动电子邮件? - Using Swift and Firebase, how can I send an automated email to myself from an authenticated user of my app? 我如何使用swift3从Firebase数据库中存储具有多个字符串的对象 - How can I store object has a multiple strings from firebase database using swift3 如何在Swift中的多个节点中观察Firebase子值的变化? - How can I observe Firebase child value changes in multiple nodes in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM