gpt4 book ai didi

ios - 使用 swift 检查 Firebase 中的用户类型

转载 作者:行者123 更新时间:2023-11-29 01:01:36 25 4
gpt4 key购买 nike

这里是 swift 和 Firebase 的初学者!我有一个看起来像这样的数据库:

数据库
玩家
ref.authdata.uid-for-player-1
ref.authdata.uid-for-player-2
ref.authdata.uid-for-player-3
教练
ref.authdata.uid-for-coach-1
ref.authdata.uid-for-coach-2
ref.authdata.uid-for-coach-3

我的应用程序有一半是为球员打造的,另一半是为教练打造的。如何检查 ref.authData.uid child 是在球员还是教练 child 之下?我的数据结构是否有误?

此外,每个 uid 下面还有更多我没有包含在图表中的子项,其中包含有关每个球员/教练的信息。下面是我用于初步构建的身份验证方法。

if ref.authData != nil  {

print("There is already a user signed in!")
self.performSegueWithIdentifier("playerLogin", sender: self)

} else {
// No user is signed in
}


感谢您的帮助!

最佳答案

tobeisdev 有一个很好的答案(我会接受),链接的答案也可以。

我也想添加一个替代方案;既然教练和球员都是用户,为什么不采用标准的 Firebase/用户设计模式

users
user_id_0
type: "player"
name: "Larry"
team: "team_id_0"
user_id_1
type: "player"
name: "Biff"
team: "team_id_0"
user_id_2
type: "coach"
name: "Benny"
team: "team_id_0"

然后你可以添加一个团队节点

teams
team_id_0
team_name: "nerds r' us"
coach: user_id_2
players:
user_id_0: true
user_id_1: true

这将使您能够查询特定的教练或球员并获取他们的 uid 以及了解该球员或教练所属的球队。您还可以组建一支球队并了解教练和球员是谁。

只是一个想法。

关于ios - 使用 swift 检查 Firebase 中的用户类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com