我正在尝试根据用户选择的类别获取用户的特定帖子。
例如,我有一个包含多个类别的 Collection View ,例如“冷肩、自行车短裤、黄金”
如果用户在帖子中使用#bikeshorts 标签,则该帖子也将出现在名为“自行车短裤”的类别中。
如何获取包含#bikeshorts 标签的照片?
这是我通过 Firebase 构建的数据库结构(总共有 2 篇帖子使用主题标签“bike shorts”)
这是我现在正在尝试但没有成功的代码
func fetchPosts() {
if trendName == "Bike Shorts" {
print("Fetching posts with the hashtag bikeshorts")
let query = HASHTAG_POST_REF.queryEqual(toValue: "bikeshorts")
query.observeSingleEvent(of: .value) { (snapshot) in
if snapshot.exists() {
let postId = snapshot.key
Database.fetchPost(with: postId, completion: { (post) in
self.posts.append(post)
self.collectionView?.reloadData()
})
}
}
}
}
最佳答案
更新 我能够得到自行车短裤的帖子! 这是我使用的代码
func fetchPosts() {
if trendName == "Bike Shorts" {
print("Fetching posts with the hashtag bikeshorts")
HASHTAG_POST_REF.child("bikeshorts").observe(.childAdded) { (snapshot) in
let postId = snapshot.key
Database.fetchPost(with: postId, completion: { (post) in
self.posts.append(post)
self.collectionView?.reloadData()
})
}
}
}
关于ios - 如何获取特定的标签帖子(更新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57244767/