On-demand resources (ODR) get completed/total file size of downloaded tag

491 views Asked by At

I'm downloading zip archives via ODR and want to show a progress and the completed/total file size to the user (like "3/10MB downloaded") Using KVO I managed to observe the fractionCompleted property of the associated Progress object, so I'm able to show a progress bar.

The code looks like that:

let request = NSBundleResourceRequest(tags: [tag])

request.progress.observe(\.fractionCompleted, options: [.new, .old]) { [weak self] _, change in
      guard let progress = change.newValue else { return }

      // Use new progress value here
}

Now, to show the completed/total file size in bytes I tried to access completedUnitCount and totalUnitCount, which happens to always have the values 1 (meaning 1 file?).

How can I obtain the correct values of completedUnitCount and totalUnitCount?

1

There are 1 answers

0
Eugene Biryukov On

That was surprise for me as well. We've managed to solve this by using the fractionCompleted property of the Progress value:

progress.fractionCompleted