Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
Retrieve Alamofire estimatedTimeRemaining & file downloaded size

I am trying to download a file using Alamofire. To show progress, i am using downloadProgress from alamofire. I got the progress percentage from it. But i need to show the total Mb/Kb downloaded so far and estimated time remaining as well. Here is my code:

AF.download("http://ipv4.download.thinkbroadband.com/200MB.zip",
                method: .get,
                parameters: nil,
                encoding: URLEncoding.default,
                headers: nil,
                interceptor:nil,
                to: destination)
                .downloadProgress { progress in
                    self.postProgress(progress: progress)
                }
                .responseData { response in
                    if let data = response.result.value {
//                        let image = UIImage(data: data)
                    }
            }

Posting the progress using notification

func postProgress(progress: Progress) {
        NotificationCenter.default.post(name: .DownloadProgress, object: progress)
    }

Showing my progress using the following codes

if let progress = notification.object as? Progress {
            progressBar.setProgress(Float(progress.fractionCompleted), animated: true)
            progressInNumberView.text = "\(Int64(progress.fractionCompleted*100))%"
            remianingView.text = "\(progress.fileCompletedCount) / \(progress.fileTotalCount)"
            if let estimatedTimeRemaining = progress.estimatedTimeRemaining {

                remianingView.text = format(estimatedTimeRemaining)
            }
        }

I am getting progress.fractionCompleted perfectly. But progress.estimatedTimeRemaining, progress.fileCompletedCount and progress.fileTotalCount is always nil.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Simple DownloadProgress class implementation based on having a Progress from Alamofire or other and a moving average taken from here How to estimate download time remaining (accurately)?

https://gist.github.com/akovalov/7b22735e1fb7f1117bf04659e214d785

over 4 years ago · Santiago Trujillo Report

0

I you check the Progress class you can find

open var totalUnitCount: Int64
open var completedUnitCount: Int64

you can use those variables

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!