Firebase,显示帖子,下一个路径为“self.dataBaseRef.child(”Posts“)。child(uid).childByAutoId()”

时间:2017-04-18 07:41:14

标签: ios swift firebase firebase-realtime-database

我必须用firebase显示帖子,帖子在路径上:

self.dataBaseRef.child("Posts").child(uid).childByAutoId()

哪里

"uid" = FIRAuth.auth()!.currentUser!.uid

dataBaseRef = FIRDatabaseReference! {
    return FIRDatabase.database().reference()
}

Firebase上的帖子发布成功,但我无法进入此路径,因为我无法声明uid因为每个用户都是特定的。怎么样?

1 个答案:

答案 0 :(得分:0)

试试这样:

let dataBaseRef = FIRDatabase.database().reference(withPath: "Posts")

dataBaseRef.observe(.value, with: { snapshot in
        for item in snapshot.children {
            let childSnap = item as! FIRDataSnapshot // do something you wants to
            // childSnap contains item in Posts. So in cycle you will catch
            // every post child node. From here you can get uid's 
            // and make a new observer
        }
})

希望有所帮助