我想将 ProgressView 的进度作为一个元素存储到 arraylist 中
我这样声明数组
var prog = [Float]()
我取得了这样的进展
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
if totalBytesExpectedToWrite > 0 {
progressVi = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)
print(progressVi)
}
}
我尝试用这个来存储它
prog.insert(progressVi, at: 0)
但我是这样理解的
[0.0071399305, 0.004518387, 0.002777841, 0.0012658517, 0.00086148235, 0.00063292583, 0.000580182, 0.0005274382, 0.0001557393]
并且还在不断添加...
那么如何将其存储为一个元素呢?
你正走向错误的方向。您需要的是获取 dataTaskprogress https://developer.apple.com/documentation/foundation/urlsessiontask/2908821-progress对象并用它来设置你的UI进度视图 https://developer.apple.com/documentation/uikit/uiprogressview 观察到的进展 https://developer.apple.com/documentation/uikit/uiprogressview/1619840-observedprogress财产。
var observedProgress: Progress? { get set }
设置此属性后,进度视图会使用从Progress https://developer.apple.com/documentation/foundation/progress目的。 (进度更新是动画的。)当您想要手动更新进度时,请将该属性设置为 nil。该属性的默认值为 nil。
有关配置进度对象以管理进度信息的更多信息,请参阅Progress https://developer.apple.com/documentation/foundation/progress.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)