Swift /当用户获得正确答案时,如何使分数增加一?

伙计们,我是Swift的新手,我目前正在学习结构模块。 每次用户正确回答时,我被要求创建一个增加1分的分数,但是我的分数最终增加2,我很困惑,其他一切都很好。有人可以帮我吗。 代码在下面。

导入UIKit

类ViewController:UIViewController {

@IBOutlet weak var questionLable: UILabel!
@IBOutlet weak var progressBar: UIProgressView!
@IBOutlet weak var trueButton: UIButton!
@IBOutlet weak var falseButton: UIButton!
@IBOutlet weak var scoreLabel: UILabel!

var quizBrain = QuizBrain()


override func viewDidLoad() {
    super.viewDidLoad()
    progressBar.progress = 0
    updatedUI()
}


@IBAction func answerButtonPressed(_ sender: UIButton) {

    let userAnswer = sender.currentTitle!        
    let userGotItRight = quizBrain.checkAnswer(userAnswer) 

    print(quizBrain.checkAnswer(userAnswer))
    if userGotItRight{              

        UIView.animate(withDuration: 0.2) {
            sender.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
        }
        UIView.animate(withDuration: 0.2) {
            sender.backgroundColor = UIColor.clear
        }
    }else{
        UIView.animate(withDuration: 0.2) {
            sender.backgroundColor = #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1)
        }
        UIView.animate(withDuration: 0.2) {
            sender.backgroundColor = UIColor.clear
        }
    }

    quizBrain.nextQuestion()
    updatedUI()
}

func updatedUI()  {
    questionLable.text = quizBrain.getQuestionText()
    scoreLabel.text = "Score:\(quizBrain.getScore())"
    progressBar.progress = quizBrain.getProgress()

}

}

下一部分是模型 进口基金会

结构QuizBrain {     让测验= [

    Question(q: "A slug's blood is green.", a: "True"),
    Question(q: "Approximately one quarter of human bones are in the feet.", a: "True"),
    Question(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"),
    Question(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True")

]
var questionNumber = 0
var score = 0

mutating func checkAnswer(_ userAnswer: String) -> Bool {
    if userAnswer == quiz[questionNumber].answer{     
        score += 1
        return true                 
    }else{
        return false
    }

}

变异func getScore()-> Int {         回报分数     }     func getQuestionText()->字符串{

    return quiz[questionNumber].text     
}
func getProgress() -> Float {
    let progress = Float(questionNumber + 1)/Float(quiz.count)
    return progress
}
mutating func nextQuestion(){
    if questionNumber + 1 < quiz.count{           
       questionNumber += 1       
    }else {
        questionNumber = 0
        score = 0
    }
}

}