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:
- In the ImageDownloader.swift file, add the following code:
class ImageDownloader: Operation...