0
votes

I have a class called Posts in which i've postedBy column where i am saving the PFUser.currentUser() (pointer). so i want to retrieve the username, profile picture and stuff from the _User class using postedBy in the Posts class. What is the shortest and efficient way to achieve this? i am not much familiar with relation queries.

1

1 Answers

0
votes

I believe that instead of saving the user pointer, you should save the user's username then it comes easier for you to retrieve everything.

var query = PFQuery(className:"Posts")
var username = PFUser.currentUser()?.username
query.whereKey("username", equalTo: username!)
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
    if error == nil
    {
        if let objects = objects as? [PFObject]
        {
            for one in objects {
               var pictureImage = one["theFile"] as! PFFile
                pictureImage.getDataInBackgroundWithBlock({ (dataToget:NSData?, error:NSError?) -> Void in
                    if error == nil {

                        if let  Image = UIImage(data: dataToget!){
                          // then you have the image
                            // save the image to array
                            // reload the tableview
                        }



                    }
               })

            }


        }


    }
}