1
Я пытаюсь показать прогресс при загрузке файла с помощью Alamofire в Swift 3 для приложения macOS.NSProgressIndicator Swift - 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, но я не могу найти ничего связанного.
EDIT:
Выход:
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
проверить это может быть поможет вам http://stackoverflow.com/questions/30385096/uiprogressview-progress-update-very-slow-within-alamofire-async-call –
Спасибо, но нет. Это не так. Это для UIProgressView для iOS, а не для NSProgressIndicator для macOS. – Batman