I want to show the progress while zipping some files with ZIPFoundation.
The zip method can take a Progress
object and continuously updates the fractionCompleted
value for that object.
I can access the progress
value with the observeValue(forKeyPath)
method but the UIProgressView
is not updated continously. The UI is updated after zipping is finished.
Setting progressView.progress
value directly or via DispatchQueue.main.async
makes no difference.
Any idea where my bug is?
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "fractionCompleted" {
let progress = object as! Progress
let progressFloat = Float(progress.fractionCompleted)
DispatchQueue.main.async {
self.progressView.progress = progressFloat
}
}
}