我正在尝试从firebase检索帖子列表(" Planits - 以我的应用语言")。我的目标是在其个人资料的表格视图中显示特定用户帖子。我编写了一个函数来检索帖子并通过发件人ID查询它们,以便用户在他们的个人资料中查看他们的帖子。但在查询结束时,当我尝试打印出附加的数组时,我不断得到一个空数组,所以我无法继续填充表视图。请关于我哪里出错的任何建议,附件是我的firebase节点的屏幕截图和我写的功能。感谢
func retrievePost(){
ref = Database.database().reference()
let myPlanitsRef = self.ref.child("planits")
let query = myPlanitsRef.queryOrdered(byChild: "senderId").queryEqual(toValue: "uid")
print(query)
query.observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists() {
for child in snapshot.children {
let snap = child as! DataSnapshot
print(DataSnapshot.self)
let dict = snap.value as! [String: Any]
let myPostURL = dict["images"] as! String
self.images.append(myPostURL)
}
//print(myPostURL) - DOES NOT PRING ANYTHING
//print(self.images) - DOES NOT PRING ANYTHING
}
}) { (error) in
print(error)
}
}
override func viewDidLoad() {
super.viewDidLoad()
retrievePost()
print(images) // PRINTS []