kareem
kareem

Reputation: 933

Parse Query Profile Data for User Profile - Swift

I want to query the user data based on the profile you are on in my app. As of now my query just gets all the posts not just the user that the profile belongs too.

"Drives" is the class name of the user posts.

 post.removeAll(keepCapacity: false)
    var findTimelineData:PFQuery = PFQuery(className:"Drives")
    findTimelineData.findObjectsInBackgroundWithBlock
        {
            (objects:[AnyObject]! , error:NSError!) -> Void in
            if error == nil
            {
                self.post = objects.reverse() as [PFObject]
                self.table.reloadData()
            }
    }

Upvotes: 0

Views: 587

Answers (1)

Dániel Nagy
Dániel Nagy

Reputation: 12045

post.removeAll(keepCapacity: false)
var findTimelineData:PFQuery = PFQuery(className:"Drives")

//Add the next line
findTimelineData.whereKey("YOUR_COLUMN_NAME_WHERE_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")


findTimelineData.findObjectsInBackgroundWithBlock
    {
        (objects:[AnyObject]! , error:NSError!) -> Void in
        if error == nil
        {
            self.post = objects.reverse() as [PFObject]
            self.table.reloadData()
        }
}

Or instead you can choose any whereKey... function, listed as here: https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/whereKey:equalTo:

UPDATED: If you query a pointer field, then the whereKey is modified a bit, you have to use relational queries:

let userNameQuery = PFQuery(className: "THE_CLASSNAME_WHERE_THE_USERS_ARE_STORED")
userNameQuery.whereKey("YOUR_COLUMN_NAME_WHERE_THE_NAME_OF_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")

let findTimelineData:PFQuery = PFQuery(className:"Drives")
findTimelineData.whereKey("POINTER_COLUMN_OF_USER", matchesQuery: userNameQuery)

Upvotes: 1

Related Questions