To work with the operation queue API instead of GCD, first we need to create an OperationQueue instance and then create an OperationQueueScheduler with that operation queue, as follows:
let opQueue = OperationQueue()let opQueueScheduler = OperationQueueScheduler(operationQueue: opQueue)
Finally, we can use the opQueueScheduler instead of the serial queue scheduler with the ObserveOn operator, as demonstrated:
imageData .observeOn(opQueueScheduler) .map { UIImage(data: $0) } .observeOn(MainScheduler.instance) .subscribe(onNext: { imageView.image = $0 }) .disposed(by: disposeBag)
The overall code for this demonstration can be summarized as follows:
import PlaygroundSupportPlaygroundPage.current.needsIndefiniteExecution ...