Downloading the Image Data

Now all that is left is downloading the image data for the photos that come back in the request. This task is not very difficult, but it requires some thought. Images are large files, and downloading them could eat up your users’ cellular data allowance. As a considerate iOS developer, you want to make sure your app’s data usage is only what it needs to be.

Consider your options. You could download the image data in viewDidLoad() when the fetchInterestingPhotos(completion:) method calls its completion closure. At that point, you already assign the incoming photos to the photos property, so you could iterate over all of those photos and download their image data then.

Although this would work, it would ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.