How to use the PFQuery for PFQueryTableViewController to retrieve an array of PFObjects?

46 views Asked by At

I have a PFUser with a Skills column.

Typically I can use user.skills (or user["skills"]) to get the skills objects of the user.

But to use these with PFQueryTableViewController I need to construct some sort of PFQuery when overriding queryForTable to get the list of skills for a user.

How do I build this query? All it does is return the skills for a given user.

1

There are 1 answers

1
cnichs27 On
fetchSkills(){
     var userQuery: PFQuery = PFUser.query()!

     userQuery.wherekey("username", equalTo: (currentUser?.username)!)

     userQuery.findObjectsInBackgroundWithBlock({
        (users, error) -> Void in

        var skills = users!


        if error == nil {
            if skills.count >= 1 {
                for i in 0...users!.count-1 {
                    self.skillTypes.append(skills[i].valueForKey("UserSkills") as! String)

                }
            }
            self.usersArray = users as! [PFUser]
            self.tableView.reloadData()
        } else {
            print(error)
        }
    })
}