'How to upload results to label in shell from swift code?
Everything is working fine, but I don't understand why the wrong label "loading" doesn't update the percentage. while i print the output value is continuously changing
do {
@discardableResult
func shell(_ args: String...) -> (String?, Int32) {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
task.waitUntilExit()
return (output, task.terminationStatus)
}
shell(....)
let strURL = "http://download.com/load.zip"
let url = URL(string: strURL)
FileDownloader(url! as NSObject).download(url: url!)
var result = ""
func checkdl() {
let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
let fileURL = dir!.appendingPathComponent("load.txt")
result = try! String(contentsOf: fileURL, encoding: .utf8)
print(result)
if result.contains("100.0") {
try! "".write(to: fileURL, atomically: true, encoding: String.Encoding.utf8)
print("download done")
} else {
sleep(2)
loading.stringValue = result+"%"
checkdl()
}
}
checkdl()
shell(....)
}
Everything is working fine, but I don't understand why the wrong label "loading" doesn't update the percentage. while i print the output value is continuously changing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
