Post

Replies

Boosts

Views

Created

Entering a maximum number of questions for quiz app
Hey everyone i'm really new to coding and am loving it so far, i've made a pretty basic quiz app although it does have just over 100 questions, the game sets an alert at the end of all 100 questions but I want it to end at say 10 or 30 and so on, heres some code would I insert here or where my questions are? thanks in advanced      let answer = question.answers[indexPath.row]     if checkAnswer(answer: answer, question: question) {       if let index = gameModels.firstIndex(where: { $0.text == question.text }) {         if index (gameModels.count + 1) {           //next question           let nextQuestion = gameModels[index+1]           print("\(gameModels.shuffle())")           currentQuestion = nil           configureUI(question: nextQuestion)           self.scoreBoard += 1           self.scoreLabel.text = String(scoreBoard)                     }         else {           //end of game           let alert = UIAlertController(title: "Done", message: "You beat the game", preferredStyle: .alert)           alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))           present(alert, animated: true)         }
0
0
395
Mar ’21
Presenting ViewController after alert
Hey everyone! Still quite new at coding so any help would be much appreciated, so I have a quiz app and there may be over 100 questions but once it gets to a certain number it sends an alert, after the alert I want it to go back to the main screen, thoughts?          if questionsAsked = 4 {           // alert user that game is over           let alert = UIAlertController(title: "Done", message: "You beat the game", preferredStyle: .alert)           alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))           present(alert, animated: true)         }
2
0
350
Mar ’21
Do not repeat question, removeAtIndex
Hey everyone really struggling with this one, I have a quiz app however I need the questions to not repeat. My var is:    var gameModels = [Question]() And then my index:          if index (gameModels.count + 1) {           //next question           print("\(gameModels.shuffle())")           let nextQuestion = gameModels[index+1]           currentQuestion = nil           configureUI(question: nextQuestion)           self.scoreBoard += 1           self.scoreLabel.text = String(scoreBoard)           questionsAsked += 1         } Any help would be greatly appreciated, cheers!
7
0
579
Mar ’21