Background Tasks

The viewContext of NSPersistentContainer is associated with the main queue. Because of this, any operations that take a long time will block the main queue, which can lead to an unresponsive application. To address this, it is often a good idea to do expensive operations on a background task. The insertion of photos from the web service is a good candidate for a background task.

You are going to update processPhotosRequest(data:error:) to use a background task. Background tasks are an asynchronous operation, so you will need to update the method signature to use a completion handler.

Open PhotoStore.swift and update processPhotosRequest(data:error:) to take in a completion handler. You will have some errors in the ...

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.