O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using BlockOperation

In this section, we will be using the same DoCalculation class that we used in the Grand Central Dispatch section to keep our queues busy with work so that we could see how the OpererationQueue class works.

The BlockOperation class is a concrete implementation of the Operation type that can manage the execution of one or more blocks. This class can be used to execute several tasks at once without the need to create separate operations for each task.

Let's see how we can use the BlockOperation class to add concurrency to our application. The following code shows how to add three tasks to an operation queue using a single BlockOperation instance:

let calculation = DoCalculations() let blockOperation1: BlockOperation = BlockOperation.init( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required