To get started with Operation queues, perform the following steps:
- Let's use the same demo, but Operation queues instead of GCD.
- 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 ...