【发布时间】:2020-06-30 00:43:50
【问题描述】:
我正在尝试查询一组用户 ID,这些用户 ID 保存在我的 Firestore 数据库中的一个数组中。这是有效的,它成功地在我的控制台中显示了 UID。然后,我想找到字段“uid”何时等于数组的成员。这是它停止工作的地方。我似乎无法将“uid”与 followUID 数组的成员实际匹配。
我在下面详细说明了我的代码。任何帮助将不胜感激:
func getFollowingPosts() {
db.collection("iAmFollowing").document(currentUserID!).getDocument { (document, error) in
if error != nil {
print("ERROR")
} else {
if let document = document {
let followedUID = document["uid"] as? Array ?? [""]
print("followed UID is \(followedUID)")
let searchedInfo = self.db.collection("posts").whereField("uid", isEqualTo: followedUID)
let refinedInfo = searchedInfo.order(by: "Alpha", descending: true)
refinedInfo.getDocuments { (documents, error) in
guard let documents = documents else {
print("NO DOCUMENTS")
return
}
for documents in documents.documents {
let title = documents.get("Title") as! String
let content = documents.get("Content") as! String
let username = documents.get("username") as! String
let postID = documents.get("postID")
let counter = documents.get("counter")
self.titleArray.append(title)
self.contentArray.append(content)
self.usernameArray.append(username)
self.postIDArray.append(postID as! Int)
self.effectsLabelArray.append(counter as! Int)
print(self.titleArray)
self.tableView.reloadData()
}
}
}
}
}
}
谢谢!
【问题讨论】:
标签: ios swift firebase google-cloud-firestore