swift4创建用户信息名称,年龄并从火力基地获取数据

时间:2019-02-09 21:29:14

标签: swift firebase

我通过登录和注册就可以很好地创建Firebase 也可以存储图像,但无法取回存储在Firebase中的图像,我想创建用户个人资料来存储用户的名称和年龄,

成功登录,将图像存储在Firebase中,并创建了实时数据库子级,例如图像用户名和年龄,但无法在我的应用程序中使用,创建用户个人资料时出现问题,以及从Firebase存储中获取图像时出现问题。

>>> list(set([tuple(sorted(x)) for x in a]) - set([tuple(sorted(x)) for x in b]))
[('d', 'e', 'h')]

我有疯狂的评论,请忽略它!

1 个答案:

答案 0 :(得分:0)

我自己为以后的编码者找到了答案,可以作为参考!   //已存储用户信息

  let userID = Auth.auth().currentUser?.uid
        let userData = ["userName": userName,
            "userAge ": userAge] as [String? : Any]


        let ref = Database.database().reference()
        ref.child("users/\(userID ?? "")").setValue(userData)



}

现在要检索数据,请创建一个结构并将代码载入视图

 func fetchCurrentUserData() {   
    guard let currentUid = Auth.auth().currentUser?.uid else { return }

    let userRef = Database.database().reference().child("users").child(currentUid)

    print("userRef: \(userRef)")

    userRef.observeSingleEvent(of: .value) { (snapshot) in
        guard let dictionary = snapshot.value as? Dictionary<String, AnyObject> else { return }
        let uid = snapshot.key
        let user = User(uid: uid, dictionary: dictionary)
        self.user = user
        print(snapshot.key)

    }
}