'my progress bar is showing 1 progress point behind then it should

So I have created a progress bar and when user selects an option from the action sheet the progress bar will increase according to the option selected (either 1, 3, 6 or 9 points) but there seems to be a point in delay, when I select a choice, the progress isn't effected, although when I print the state of the progress, the value goes up accurately, and then when I select another option (lets say higher points options) the progress bar gets filled by the amount of the previous selection, so its always one step behind, not sure what to do, but here is some of my code.

class StateViewController: UIViewController {

var toNextLevel = 10
var xpGained = 0

@IBOutlet var enduranceNumber: UILabel!

// Main Progress Bars

@IBOutlet var levelProgressBar: UIProgressView!

@IBOutlet var healthProgressBar: UIProgressView!

@IBOutlet var skillsProgressBar: UIProgressView!

@IBOutlet var poiseProgressBar: UIProgressView!

// Level Progress Bars

@IBOutlet var enduranceProgressBar: UIProgressView!

@IBOutlet var strengthProgressBar: UIProgressView!

@IBOutlet var intelligenceProgressBAR: UIProgressView!

@IBOutlet var flexibilityProgressBar: UIProgressView!


// Skill Progress Bars

@IBOutlet var socialProgressBar: UIProgressView!

@IBOutlet var programmingProgressBar: UIProgressView!

@IBOutlet var strikingProgressBar: UIProgressView!

@IBOutlet var grapplingProgressBar: UIProgressView!



override func viewDidLoad() {
    super.viewDidLoad()

    
    enduranceProgressBar.progress = Float(xpGained) / Float(toNextLevel)
    
    if enduranceProgressBar.progress == 10 {
        enduranceProgressBar.progress = 0.0
    }
    
 print("\(xpGained)")
    
    
    
    
}


func enduranceProgressEasy() {
    
    let percentageProgress = Float(xpGained) / Float(toNextLevel)
    enduranceProgressBar.progress = Float(percentageProgress)
    
    print("Floating")
    
    if xpGained < toNextLevel + 1{

       
         xpGained += 1
        print("\(xpGained) xpGained 1")
} else if xpGained == toNextLevel + 1 {
  
 
    enduranceProgressBar.progress = 0.0
    xpGained -= toNextLevel
    
    print("No Issues")
    switch enduranceNumber.text {
    case "1":
        enduranceProgressBar.progress = 0.0
        
        toNextLevel += 3
        enduranceNumber.text = "2"
       
    case "2":
        enduranceProgressBar.progress = 0.0
         xpGained = 1
       
        toNextLevel += 3
        enduranceNumber.text = "3"
    case "3":
        enduranceProgressBar.progress = 0.0
        
         xpGained = 1
        toNextLevel += 3
        enduranceNumber.text = "4"
    case "4":
        enduranceProgressBar.progress = 0.0
        xpGained = 1
        toNextLevel += 3
        enduranceNumber.text = "5"
    case "5":
        enduranceProgressBar.progress = 0.0
        xpGained = 1
        toNextLevel += 3
        enduranceNumber.text = "6"
  
    default:
        print("Something went wrong")
    }
    
} else {
    xpGained += 1
}



}



func enduranceProgressLight() {
    
    let percentageProgress = Float(xpGained) / Float(toNextLevel)
    enduranceProgressBar.progress = Float(percentageProgress)
    
    print("Floating")
    
    if xpGained < toNextLevel + 1{

       
         xpGained += 3
        print("\(xpGained) xpGained 3")
} else if xpGained == toNextLevel + 1 {
  
 
    enduranceProgressBar.progress = 0.0
    xpGained -= toNextLevel
    
    print("No Issues")
}

}



// Create UIAlert controller in replace of UIVIEWS



@IBAction func enduranceButton(_ sender: UIButton) {
    
    
    
    let alert = UIAlertController.init(title: "Exceed", message: nil, preferredStyle: .actionSheet)
    
    alert.addAction(UIAlertAction(title: "Easy +1", style: .default, handler: { _ in self.enduranceProgressEasy() }))
    alert.addAction(UIAlertAction(title: "Light +3", style: .default, handler: { _ in self.enduranceProgressLight() }))
    alert.addAction(UIAlertAction(title: "Hard +6", style: .default, handler: { _ in self.enduranceProgressBar.progress += 0.6 }))
    alert.addAction(UIAlertAction(title: "Intense +9", style: .default, handler: { _ in self.enduranceProgressBar.progress += 0.9 } ))
    
    
    
    self.present(alert, animated: true, completion: nil )
    

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source