在斯威夫特,你如何执行一个查询之前,另一对PFQueryTableViewController解析? [英] In Swift, how do you execute one query to Parse before another on PFQueryTableViewController?

查看:265
本文介绍了在斯威夫特,你如何执行一个查询之前,另一对PFQueryTableViewController解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做两个查询,我PFQueryTableViewController解析。我试图做一个查询来获取所有有关中的currentUser对象,然后将这些物品放入一个数组。数组充满了它的对象后,我想从另做查询

I am trying to do two queries to Parse in my PFQueryTableViewController. I am trying to do one query to obtain all of the objects relating to the currentUser and then place those objects into an array. After the array is filled with its objects, I would like to do another query from

override func queryForTable() -> PFQuery { }. 

此第二查询将使用从被来自第一查询创建阵列的对象,以便检索其自己的对象。

This second query will use the objects from the array that was created from the first query, in order to retrieve objects of its own.

我不知道如何让前一秒第一个查询执行。截至目前,第二个查询将第一个之前它有机会填补阵列之前执行,因此搅乱了第二个查询。下面是我在这一点上我的code。

I don't know how to make the first query execute before the second. As of right now, the second query will execute before the first one before it has a chance to fill the array and as a result messes up the query for the second one. The following is what i have for my code at this point.

class PFNewsFeedTableViewController: PFQueryTableViewController {

var leadersArray : NSMutableArray = NSMutableArray()

override func viewDidAppear(animated: Bool) {
    leadersArray.removeAllObjects()

    var findLeaders = PFQuery(className: "Follow")

    findLeaders.whereKey("follower", equalTo: PFUser.currentUser()!)
    findLeaders.orderByDescending("createdAt")
    findLeaders.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        //If no error
        if error == nil {

            println("Successfully retrieved \(objects!.count) leaders.")

            // Do something with the found objects
            if let objects = objects as? [PFObject] {

                for object in objects {

                    self.leadersArray.addObject(object.objectForKey("leader")!)

                }

            }

        }
        self.tableView.reloadData()

        self.queryForTable()
    }

}



override func queryForTable() -> PFQuery {

    var findContent = PFQuery(className: "Content")
    findContent.whereKey("user", containedIn: self.leadersArray as [AnyObject])
    findContent.orderByDescending("createdAt")

    return findContent
}    

}   

有没有办法来确定这些查询得到执行的顺序?对这个问题的任何帮助将是AP preciated。

Is there a way to determine the order in which these queries get executed? Any help to this problem would be appreciated.

推荐答案

我想通了这个问题,它看起来像这样

I figured out the problem and it looks like this

override func queryForTable() -> PFQuery {

    var findLeaders = PFQuery(className: "Follow")
    findLeaders.whereKey("follower", equalTo: PFUser.currentUser()!)
    findLeaders.orderByDescending("createdAt")

    var findContent = PFQuery(className: "Content")
    findContent.whereKey("user", matchesKey: "leader", inQuery: findLeaders)
    findContent.orderByDescending("createdAt")


    return findContent
}

这篇关于在斯威夫特,你如何执行一个查询之前,另一对PFQueryTableViewController解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆