TomTom
TomTom

Reputation: 909

PFQueryTableViewController, asynchronous and synchronous loading for queries Parse swift

Currently working on a way to load my queries before the table loads, currently the array doesn't hold anything before the page loads. Segue from previous page is not an option as i've got many segues leaving this page. Still new to Parse is there a way to complete this query before the table loads.

override func queryForTable() -> PFQuery! {

    var query = PFQuery(className: "Tasks")
    switch (segmentControl.selectedSegmentIndex){

    case 0:
        var unfinishedTaskQuery = PFQuery(className: "Students")
        unfinishedTaskQuery.whereKey("username", equalTo: PFUser.currentUser().username)
        unfinishedTaskQuery.getFirstObjectInBackgroundWithBlock({ (object: PFObject!, error: NSError!) -> Void in

                self.tasks = object["taskIDs"].copy() as [Int]


            self.completedTasks = object["completedTaskIDs"].copy() as [Int]
            self.loadObjects()

        })

        query = PFQuery(className: "Tasks")

        query.whereKey("taskID", containedIn: self.tasks)
        // Add a where clause if there is a search criteria

        query.orderByAscending("taskDetail")
   return query



    case 1:

        query.whereKey("taskID", containedIn: completedTasks)
        println("tasks")
        // Add a where clause if there is a search criteria
        println("yes")
        query.orderByAscending("taskDetail")

        return query
    default:
        break;

    }

    return query
}

Upvotes: 1

Views: 236

Answers (1)

TomTom
TomTom

Reputation: 909

Thought it was a simple fix, although this does cause a "long running operation on the main thread"

 var object = unfinishedTaskQuery.getFirstObject()

If anyone knows how i could maybe achieve this without the long running warning that would still be appreciated.

Upvotes: 1

Related Questions