I doing some HTTP request, setting a class property when the HTTP response is received and updating a progress bar value with willSet
. The progress bar animation works only once.
var data: CompatibilityData? {
didSet {
self.progressView.setProgress(0.0, animated: false)
UIView.animate(withDuration: 2.0) {
self.progressView.setProgress(data.percentage! / 100, animated: true)
}
}
}
...
let task = URLSession.shared.dataTask(with: url) { data, response, error in
...
if let data = data {
...
DispatchQueue.main.async {
if let r = response {
self.data = r
}
}
}
}
task.resume()
When I'll receive HTTP response a second time, the expected behavior reset progress to 0 and animate it from 0 to data.percentage
again. Currently it moves from old data.percentage
to new data.percentage
.