Need help with Swift 4.2

Hi, I have started learning Swift recently and due to system specifications, I am learning how to build apps for iOS 12.
I have written a code to update UI based on user's click.
Note : This function is called in the IBAction Function
Code Block func updateUI() {
    //Here i is a global variable
    scoreLabel.text = "Score : \(score)"
     
    progressLabel.text = "Question: \(questionNumber+1) / 13"
     
    progressBar.frame.size.width = (CGFloat(view.frame.size.width) / 13) * CGFloat(i)
    print("i: \(i)")
    i = i + 1
      //CGFloat(allQuestion.list.count) * CGFloat(questionNumber + 1)
    print(progressBar.frame.size.width)
 }

But the progress bar frame is not getting updated. I checked and the value is getting updated but when I check on simulator, the progress bar is not updating, rest all are fine.

Kindly help me out to solve this issue

Please show the complete code of your function.
What is progressBar ? Is it a UIView ?

Try adding this at line 7:
Code Block
progressBar.setNeedsDisplay()



I know exactly what course you're following ;) I'm here on this specific thread, having the exact same issue. The answer provided by Claude31 does not work.

Tagging along for the right answer.
@DikkeBana 

Without more code and details on what you get and what you expect, it is pretty hard to tell where the error is.
So I need to guess:
  • the update occurs in a loop

  • the frame is updated only at the end of loop

Is it exact ?

If so, you need to:
  • execute in another thread

  • and return to main thread for updating the frame.

See my answer for a similar issue in this other thread:
https://developer.apple.com/forums/thread/678507
Need help with Swift 4.2
 
 
Q