Im developing an iOS quiz app and the user is presented a label that displays an array containing the quiz questions. Each question is displayed at random from the array and if the right answer is selected it segues to one screen, if the wrong answer is selected it segues to another. However, the code is currently setup to where if all the questions are answered correctly and all the questions from the array are displayed, then the questions are displayed again in a random order. But I want to perform a specific segue after all the questions in the array have been answered correctly and displayed that signals that all the questions have been correctly answered, so what would be the best way to check to see if all the questions have been answered? Thanks for the help in advance.
//
func randomQuestion() {
if questionList.isEmpty {
questionList = Array(QADictionary.keys)
}
let rand = Int(arc4random_uniform(UInt32(questionList.count)))
questionLabel.text = questionList[rand]
//matching answer values to go with question keys
var choices = QADictionary[questionList[rand]]!
questionList.remove(at: rand)
}
func finalAnswer() {
if answer == true {
print("True")
performSegue(withIdentifier: "correctSeg", sender: self)
timer.invalidate()
nextQuestion += 1
currentQuestion += 1
}
else {
print("False")
performSegue(withIdentifier: "incorrectSeg", sender: self)
questionList = []
timer.invalidate()
currentQuestion = 1
}
Aucun commentaire:
Enregistrer un commentaire