0

I was wondering how how exactly Parse loads PFFile data when you use getData() or any of its background equivalents. Here's my case:

I have a User class with a key profilePic, which is a PFFile, in this case a .JPG image. When I load my user I want to display his profile picture into a UIImageView. Here's the code I use:

let imageFile = user["profilePic"] as PFFile
let imageData = imageFile.getData()
let image = UIImage(data: imageData)

I then proceed to set the image to the UIImageView in a UITableViewCell.

As you can see I'm using getData() instead of getDataInBackgroundWithBlock(), where I would set the image in the completion block.

The thing is, I get a warning that I am blocking the main thread, but I notice absolutely no lag whatsoever when I scroll through my table rapidly, thus triggering getData() often. I also see no network indicator in the status bar, which would indicate it's pulling the image file from Parse repeatedly.

In summary my question is this: how exactly does parse load my image file when it loads the user? Does it download the image file when it gets all the user info and store it in the cache? Or does it just load the reference to the file, after which it downloads the file whenever I call getData()?

Thanks in advance.

1 Answers1

0

Parse downloads a reference to the image file, and when you call getData() it downloads the contents of the file. When your query is called, all the references are saved (counting as one query). Then, each time you call getData() it counts as another API request because it needs to go to the server and download the contents of the downloaded reference. Source

If you had a slow internet connection, you might notice problems when you call getData() on the main thread.

getData() gets the data from cache if available or fetches its contents from the Parse servers.

Dehli
  • 5,950
  • 5
  • 29
  • 44