O'Reilly logo

Mastering iOS 10 Programming by Donny Wals

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

Creating reusable tasks with Operations

We just explored dispatch queues and how we can use them to schedule tasks that need to be performed on a different thread. You saw how this speeds up code and how it avoids blocking the main thread. In this section, we're going to take this all one step further. The first reason for this is because our asynchronous work would be better organized if we have an object that we can schedule for execution rather than a closure. Closures pollute our code and they are much harder to reuse.

The solution to this is using an Operation instead of a closure. And instead of queueing everything in a dispatch queue, we should queue our Operation instances on an OperationQueue. The OperationQueue and the DispatchQueue

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