NSProgressIndicator Swift - Alamofire
NSProgressIndicator Swift - Alamofire
我试图在 Swift 3 中为 macOS 应用程序使用 Alamofire 下载文件时显示进度。
这是我拥有的:
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
回答
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 { progress in
print("Download Progress: \(progress.fractionCompleted)")
self.progressIndicator.doubleValue = progress.fractionCompleted
}
}
.responseJSON { response in
debugPrint(response)
}
}
我试图在 Swift 3 中为 macOS 应用程序使用 Alamofire 下载文件时显示进度。
这是我拥有的:
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
回答
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 { progress in
print("Download Progress: \(progress.fractionCompleted)")
self.progressIndicator.doubleValue = progress.fractionCompleted
}
}
.responseJSON { response in
debugPrint(response)
}
}