How to do it...

To get started with Operation queues, perform the following steps:

  1. Let's use the same demo, but Operation queues instead of GCD.
  2. Add the following function to call it instead of the loadImages() function:
 func loadImagesWithOperationQueues(){ let queue = OperationQueue() queue.name = "Loaidng Images Queue" let operation1 = BlockOperation { let data = try! Data(contentsOf: URL(string: self.url1)!) OperationQueue.main.addOperation { self.imageView1.image = UIImage(data: data) } } queue.addOperation(operation1) let operation2 = BlockOperation { let data = try! Data(contentsOf: URL(string: self.url2)!) OperationQueue.main.addOperation { self.imageView2.image = UIImage(data: data) } } queue.addOperation(operation2) let operation3 ...

Get iOS 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.