[英]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.