I want to store the progress of progressView into arraylist as one element
I decleared the array like this
var prog = [Float]()
and i’m getting the progress like this
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
if totalBytesExpectedToWrite > 0 {
progressVi = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)
print(progressVi)
}
}
I tried this to store it
prog.insert(progressVi, at: 0)
but I’m getting it like this
[0.0071399305, 0.004518387, 0.002777841, 0.0012658517, 0.00086148235, 0.00063292583, 0.000580182, 0.0005274382, 0.0001557393]
and it’s keep adding …
So how can I store it as one element?
2
Answers
Store single element
To store it as single element of the array simply:
If you insert the item at
0
, the array will grow up every time you insert an element.Store multiple elements
In order to store multiple progresses it is necessary to create a model to store the queue.
It is necessary to store the ID for every item you are registering the progress. If you have the ID, then you can update the item progress:
You are going to the wrong direction. What you need is to get the dataTask progress object and use it to set your UIProgressView observedProgress property.