我如何使用Firebase查询订购2次

时间:2018-10-01 10:39:32

标签: swift firebase firebase-realtime-database

是否可以使用Firebase查询2次?我首先想将得分最高的帖子放在首位,然后再像我一样过滤他们的年龄。如果运行此命令,则会收到“线程1:信号SIGABRT”错误。我怎样才能解决这个问题?

func observeAllAgePosts(completion: @escaping (Post) -> Void) {
            REF_POSTS.queryOrdered(byChild: "points").queryStarting(atValue: 0)
                .queryEnding(atValue: 100000).queryOrdered(byChild: "Age").queryStarting(atValue: Age11)
                .queryEnding(atValue: Age22).observeSingleEvent(of: .value, with: {
                    snapshot in
                    if snapshot.hasChildren(){
                    let arraySnapshot = (snapshot.children.allObjects as! [DataSnapshot]).reversed()
                    arraySnapshot.forEach({ (child) in
                        if let dict = child.value as? [String: Any] {
                            let post = Post.transformPostPhoto(dict: dict, key: child.key)
                            completion(post)
                        }
                    })
                    }else{
                        ProgressHUD.dismiss()
                    }
                })
        }

我的结构:

enter image description here

0 个答案:

没有答案