Swift 如何创建多页表单并将数据保存到 Firebase?
我已经成功安装Firebase并使用UID连接登录和注册。如果用户在应用程序中保存其他数据,我现在想将其分配给登录的相应用户,最好的方法是什么?抱歉,我是 Swift 和 Firebase 的初学者,我需要一个不太复杂的教程或解释。
谢谢大家
- Ukit
- Swift 5
- Firebase
I have successfully installed Firebase and connected the login and registration with UID. If the user saves additional data in the app, I would now like to assign this to the respective user who is logged in, what is the best way to do this? Sorry I'm a beginner in Swift and Firebase, I need a tutorial or an explanation that is not too complex.
Thank you all
- Uikit
- Swift 5
- Firebase
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有这一切都假设您已将 Firebase UserAuth 连接到您的应用程序和设置。
所有用户都有一个 UID(用户标识符)来唯一标识他们。这很容易得到。
简而言之,要存储用户独有的数据,请使用 Firestore 将其全部存储在 uid 下。如果您没有 Firestore,请开始使用 Firestore。
您保存到 Firestore 的所有数据都必须采用字典格式构建,其中 String 作为键,Any 作为值。例如,如果我想为用户存储最喜欢的 3 种冰淇淋口味,您可以这样做 *注意 firebase 会自动为您创建这些文档和集合(如果它们不存在),所以不要惊慌 *:
现在,当如果您想检索此数据,您可以访问用户集合,即登录用户的集合,然后读取 favoriteFlavors 文档 - 像这样:
因此,如果您想获得排名第一的最喜欢的风味,您可以这样做:
授予,这可能会变得更加复杂,但是这是您需要了解的内容的坚实基础。我建议阅读添加数据和获取数据 Firestore 文档页面。
All of this is assuming you have Firebase UserAuth connected with your app and setup.
All users have a UID, user identifier, that uniquely identifies them. This is easy to get.
Simply put, to store data that is unique to the user, store it all under the uid using Firestore. If you do not have Firestore, get started with Firestore.
All data you save to Firestore, must be structured in a dictionary format with String as the key and Any as the value. For example, if I wanted to store the top 3 favorite flavors of ice cream for a user, you would do this *note firebase will create these documents and collections for you automatically if they do not exist so do not panic *:
Now, when you want to retrieve this data, you do access the users collection, the collection of the logged in user, then read the favoriteFlavors document--like this:
So if you wanted to get the number one favorite flavor, you would do this:
Granted, this can get more convoluted, but this is a solid foundation of what you need to know. I advice reading the add data and get data pages of the Firestore documentation.