I m trying to show some long running task progress using UIProgressView.
This is my complete and only class:
class ViewController: UIViewController {
var tempValuesArray = NSMutableArray ()
@IBOutlet weak var progressView: UIProgressView!
@IBOutlet weak var progressLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
progressView.progress = 0.0
}
override func viewDidAppear(_ animated: Bool) {
setTempData()
}
func setTempData() {
var i = 0
while i < 100000 {
tempValuesArray.add("Test String")
i += 1
}
testItNow()
}
func testItNow() {
var i = 0
var prog : Float = 0.10
let step : Float = (Float(1.0) / Float(tempValuesArray.count)) * 0.90
print(step)
while i < tempValuesArray.count {
print("***---***")
print(prog)
self.progressView.setProgress(prog, animated: true)
progressLabel.text = String(prog)
prog += step
i = i + 1
print("@@@---@@@")
}
}
}
Problem is
ProgressView and Label are updating instantly at the end
I want them to update with the loop running... To show the real progress...
Am I doing something wrong?
Or is there any other way to acheive this.