Reputation: 325
This one is a real head scratcher, I am using an operation queue like so:
let queue = OperationQueue()
queue.qualityOfService = .userInteractive
queue.addOperation {
generator = BillGenerationv3(procedures: procedure)
batchPrinting = true
if generator!.generateBills(pInfo: pInfo, cInfo: cInfo, view: self) {
DispatchQueue.main.async { // Correct
self.progressBar.progress = Float(count/uidPrecentage)
self.title = "Batching Claims \(count)/\(uidPrecentage)...Please Wait"
nextClaim()
}
}
}
It updates the title perfectly, yet the progress bar does nothing until the end. What am I doing wrong?
Upvotes: 0
Views: 50
Reputation: 2587
let someInt: Int = 3
let someOtherInt: Int = 5
This will not work
print(Float(someInt/someOtherInt))
//"0.0"
This will
print(Float(someInt)/Float(someOtherInt))
//"0.6"
The reason being that in the first scenario you're initializing a Float with the result of integer division which causes the result to be rounded to an integer by the nature of the operation.
The second scenario involves explicitly dividing two floating point numbers so the result will therefore also be a float and handle decimal numbers.
Upvotes: 2
Reputation: 1232
First of all, make sure your values count
and uidPrecentage
return valid ones (according to your estimations) and the calculus is 0 <= value <= 1.
Last but certainly not least, you should be using the progress view's class method setProgress(_ progress: Float, animated: Bool)
to update it instead of modifying directly the variable. As seen in the official documentation https://developer.apple.com/documentation/uikit/uiprogressview/1619846-setprogress, it even hands you for free the progress animation should you want
Upvotes: 1