【发布时间】:2017-06-02 21:18:10
【问题描述】:
我正在尝试在 Swift 3 中使用 Alamofire 为 macOS 应用程序下载文件时显示进度。
这是我所拥有的:
func downloadFile() {
progressIndicator.isHidden = false
progressIndicator.minValue = 0
progressIndicator.maxValue = 10
progressIndicator.isIndeterminate = false
outputTextField.stringValue = ""
let mainURL = "https://somethinghere.org/macos/\(comboCellBox.stringValue)"
let destination = DownloadRequest.suggestedDownloadDestination(for: .downloadsDirectory)
Alamofire.download(mainURL, to: destination)
.downloadProgress(queue: DispatchQueue.global(qos: .utility)) { progress in
print("Download Progress: \(progress.fractionCompleted)")
// I want to show progress from .fractionCompleted to NSProgressIndicator here
}
.responseJSON { response in
debugPrint(response)
}
}
对于每个 .fractionCompleted,我希望 NSProgressIndicator 显示下载进度并设置动画。
我不知道从哪里开始,我想知道是否有人可以帮助我开始。我已阅读 Alamofire 文档,但找不到任何相关内容。
编辑:
输出:
print("Download Progress: \(progress.fractionCompleted)")
看起来像这样:
Download Progress: 0.00208984202190035
Download Progress: 0.198987043477936
Download Progress: 0.298296286511484
Download Progress: 0.397831087926645
Download Progress: 0.49933983672564
Download Progress: 0.598874638140801
Download Progress: 0.698409439555962
Download Progress: 0.797944240971122
Download Progress: 0.897479042386283
Download Progress: 0.997013843801444
Download Progress: 1.0
回答:
self.progressIndicator.doubleValue = progress.fractionCompleted
【问题讨论】:
-
检查这个可能对你有帮助stackoverflow.com/questions/30385096/…
-
谢谢,但没有。它不会。这适用于 iOS 的 UIProgressView,而不是 macOS 的 NSProgressIndicator。
标签: swift macos swift3 alamofire nsprogressindicator