iOS 13 introduced the progress property in the OperationQueue class. At the same time Apple marked the operations and operationCount properties as deprecated which indicates they should not be used anymore for reporting progress on a queue.
My problem is that I cannot get the progress property to work as I expect it to work (which is basically out of the box). Also I could not find any documentation regarding this new property (other than that it now exists).
I tried to get it to work in a new SingleView project that has one UIProgressView on the main UIViewController. This sample is heavily inspired by https://nshipster.com/ios-13/.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var progressView: UIProgressView!
private let operationQueue: OperationQueue = {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = 1
queue.underlyingQueue = .global(qos: .background)
return queue
}()
override func viewDidLoad() {
super.viewDidLoad()
self.progressView.observedProgress = operationQueue.progress
self.operationQueue.cancelAllOperations()
self.operationQueue.isSuspended = true
for i in 0...9 {
let operation = BlockOperation {
sleep(1)
NSLog("Operation \(i) executed.")
}
self.operationQueue.addOperation(operation)
}
}
override func viewDidAppear(_ animated: Bool) {
self.operationQueue.isSuspended = false
}
}
The console shows that the queue is running as expected (as a serial queue), but there is no movement on the progress bar.
Also KVO on the progress property directly does not work, so I suspect the progress property of the OperationQueue to be the cause of the problem rather than the UIProgressView.
Any idea what I am missing here? Or could it be a bug in iOS 13? The problem exists in the simulator as well as on an iPhone 6s Plus, both running iOS 13.3.1. Thanks!