gpt4 book ai didi

swift - NSProgressIndicator Swift - Alamofire

转载 作者:行者123 更新时间:2023-11-28 06:26:30 24 4
gpt4 key购买 nike

我试图在 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

最佳答案

回答

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 - NSProgressIndicator Swift - Alamofire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41720369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com