我必须用firebase显示帖子,帖子在路径上:
self.dataBaseRef.child("Posts").child(uid).childByAutoId()
哪里
"uid" = FIRAuth.auth()!.currentUser!.uid
dataBaseRef = FIRDatabaseReference! {
return FIRDatabase.database().reference()
}
Firebase上的帖子发布成功,但我无法进入此路径,因为我无法声明uid
因为每个用户都是特定的。怎么样?
答案 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
}
})
希望有所帮助