0

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
        }
    }
   }
qtmfld
  • 2,916
  • 2
  • 21
  • 36
Thoms
  • 201
  • 2
  • 13
  • 1
    How did you set up (update) Progress? Did you try to print `progressFloat` in above callback, is it really progressing from 0 to 1? And... is self.progressView present, not nil? – Asperi Aug 31 '20 at 06:06
  • Thanks for the hint but it was a thread problem: I did the zipping on the main thread which was blocking my whole UI. By putting the zip Function in the background with **DispatchQueue.global(qos: .background).async { zipThis }** everything works fine. – Thoms Aug 31 '20 at 09:42

0 Answers0