Swift - How to update ProgressView using while loop?

It's my first iOS app and I want to update ProgressView using while loop. I need help, It's not working says "UI element cannot be updated in background thread"

Code Block
func update() {
        DispatchQueue.global().async {
            var current:Int = 0
            let total = 100
            while (current < total) {
                current += 1
                self.progress.setProgress(Float(current / total), animated: true)
                self.text.text = "Hello: " + String(current)
                print(Float(current / total))
                sleep(UInt32(0.1))
            }
        }
    }

Answered by Claude31 in 657559022
Update must occur in main thread

Code Block
func update() {
DispatchQueue.global().async {
var current:Int = 0
let total = 100
while (current < total) {
current += 1
                DispatchQueue.main.async {  // To update UI
self.progress.setProgress(Float(current / total), animated: true)
self.text.text = "Hello: " + String(current)
print(Float(current / total))
}
sleep(UInt32(0.1))
}
}
}

Accepted Answer
Update must occur in main thread

Code Block
func update() {
DispatchQueue.global().async {
var current:Int = 0
let total = 100
while (current < total) {
current += 1
                DispatchQueue.main.async {  // To update UI
self.progress.setProgress(Float(current / total), animated: true)
self.text.text = "Hello: " + String(current)
print(Float(current / total))
}
sleep(UInt32(0.1))
}
}
}

Swift - How to update ProgressView using while loop?
 
 
Q