Ok, I have looked at Displaying download progress in reusable cells but am running into an issue using URL Session to track download progress across tableview cells, after reloading the table:
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
if totalBytesExpectedToWrite > 0 {
let progress = Float(Double(totalBytesWritten) / Double(totalBytesExpectedToWrite))
itemsDownloadingNow[(downloadTask.originalRequest?.url)!] = progress
//update
for (i, prog) in itemsDownloadingNow
{
if(i.lastPathComponent == episode?.enclosure?.url.lastPathComponent)
{
//is downloading
circleProgress?.percentage = prog
}
}
}
}
This is what I've tried so far (this is in the TableViewCell class), storing the progress for each task by URL in a global dictionary: var itemsDownloadingNow = [URL: Float]()
This works if the table is NOT reloaded (the cells are shuffled), but AFTER reloading the circle progress goes back to zero/doesn't track. I don't know how to properly do this, and the only way to continuously update the circle is putting it in this URL session func.
How can I track the download progress per cell?