Most often, operations that you need to perform are better encapsulated in a custom subclass of the Operation class. We have already worked with BlockOperation in the previous demo, but we saw a lot of redundancy in writing code and it's not customized. In this section, we will implement the same demo and see how we build a custom Operation class to perform the task that will be done concurrently.
Using Operation subclassing
How to do it...
To build a custom Operation class, perform the following steps:
- In our Xcode project, add a new Swift file with a class, named ImageDownloader, which extends the Operation class:
![](https://static.packt-cdn.com/products/9781786460981/graphics/assets/22d6295b-5f3e-42ed-aa56-3fd940ed3238.png)
- In the ImageDownloader.swift file, add the following code:
class ImageDownloader: Operation...