Skip to content

Loading Images Stored on Parse

Parse developers love using our framework to store images. Be it photos taken by app users, or static asset pictures too big to ship with the app, a large number of images are uploaded to Parse daily using the PFFile API.

Displaying a remote image in an iOS app, however, is far from a walk in the park. Lots of boilerplate code is needed to first download the image, cache it on disk and in memory, and then decode and display it in an image view. Moreover, the developer needs to be careful about dispatching work to the background thread or the main thread, to keep the UI responsive. This is a lot of work.

Today, we are introducing a new class that makes downloading and displaying these images really easy. Introducing PFImageView:

PFImageView *creature = [[PFImageView alloc] init];
creature.image = [UIImage imageNamed:@"1.jpg"]; // placeholder image
creature.file = (PFFile *)file;
[creature loadInBackground];

The PFImageView class inherits from UIImageView, and is simple to use. You assign a placeholder image to its image property, so that the placeholder is displayed before the remote image is downloaded. Then you assign a PFFile object, which is the remote image stored on Parse, to its file property. When you are ready to load the image, call loadInBackground to initiate the download. That's it. When the download finishes, Parse does the work to update the image view and display the remote image.

Since Parse does both memory and disk caching, you get the benefit of both without doing any extra work. For example, if you are loading from the same PFFile twice, Parse is going to look for it in memory and in the disk cache first before attempting to download the file.

More information can be found in our documentation. And as always, your feedback is welcome.