ios - 如何获取特定的标签帖子(更新)

标签 ios swift firebase firebase-realtime-database fetch

我正在尝试根据用户选择的类别获取用户的特定帖子。

例如,我有一个包含多个类别的 Collection View ,例如“冷肩、自行车短裤、黄金”

如果用户在帖子中使用#bikeshorts 标签,则该帖子也将出现在名为“自行车短裤”的类别中。

如何获取包含#bikeshorts 标签的照片?

这是我通过 Firebase 构建的数据库结构(总共有 2 篇帖子使用主题标签“bike shorts”)

enter image description here

这是我现在正在尝试但没有成功的代码

 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/

相关文章:

ios - 如何在正确启动前从后台加载服务器数据

javascript - 如何在 Firestore 中递归搜索结果?

ios - WKWebView:是否可以预加载多个 URL?

ios - 'state changing' APNS 失败时的应用架构

macos - Webview 不显示加载的内容

swift - Vapor 4 不区分大小写的查询

ios - Firebase 动态链接在 safari swift 中不起作用

android - 无法解析 : com. google.firebase :firebase-firestore:16. 0.1

ios - 如何在自动布局或快速中自动显示多行内容?

ios - AVFoundation -AVCaptureSession 仅在进入后台并返回断点时停止并开始运行