I use the values from the progress handler to set the progress in a loading bar. This works great for the first download of an image but then produces what feel like semantically incorrect values on resumed downloads of that same image.
class PrototypeViewController: UIViewController {
private let imageView = UIImageView()
private var imageTask: ImageTask?
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
let startButton = UIButton()
view.addSubview(startButton)
startButton.setTitle("Start", for: .normal)
startButton.addTarget(self, action: #selector(startDownload), for: .touchUpInside)
let buttonHeight: CGFloat = 40
startButton.frame = CGRect(x: 0, y: buttonHeight, width: view.bounds.width, height: buttonHeight)
let cancelButton = UIButton()
view.addSubview(cancelButton)
cancelButton.setTitle("Cancel", for: .normal)
cancelButton.addTarget(self, action: #selector(cancelDownload), for: .touchUpInside)
cancelButton.frame = CGRect(x: 0, y: buttonHeight * 2, width: view.bounds.width, height: buttonHeight)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
imageView.frame = view.bounds
}
@objc private func startDownload() {
let url = URL(string: "https://apod.nasa.gov/apod/image/1809/Broom_Pickering_milne_APODw1200.jpg")!
imageTask = Nuke.loadImage(
with: url,
into: imageView,
progress: { _, completed, total in
let progress = (CGFloat(completed) / CGFloat(total)) * 100
print("Progress:", progress, "Completed:", completed, "Total:", total)
},
completion: { (response, error) in
print("Completed")
})
}
@objc private func cancelDownload() {
imageTask?.cancel()
}
}
I use the values from the progress handler to set the progress in a loading bar. This works great for the first download of an image but then produces what feel like semantically incorrect values on resumed downloads of that same image.
To reproduce:
Simple example:
Is there a setting I can change to alter this behaviour?
Cheers