How to do it...

Let's recap how we broke the work down into independent parts:

We can turn each of these blocks of work into separate operations. First, let's create an operation to scale and crop each photo.We define an operation by sub-classing the Operation class, so in the project, create a new Swift file and call it PhotoResizeOperation.swift.

In the simplest Operation implementation, we only need to override one method, main(), so let's copy and paste the relevant code from our generatePhotobook method. This main() method will be executed when the operation starts:

import UIKitclass PhotoResizeOperation: Operation {        override func main() ...

Get Swift 4 Programming Cookbook 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.