0

I am using the following code in a quiz, where once the user answers the question an alert pops up. They then have the option to go to the next question OR review the question again and then after a time period the next question appears.

The issue I am having is that this action carries on to the next question and skips it after the time period, not allowing the user time to answer it! Whats the best way to stop the action repeating automatically in the following questions?

    func nextTapped() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
            nextQuestion()
        }
    }

    func continueTapped() {
        nextQuestion()
    }
 .alert(isPresented: $showingFeedback) {
                    Alert(
                        title: Text(scoreTitle),
                        message: Text(selectedQuestion!.feedback),
                        primaryButton: .default(Text("Review"), action: nextTapped),
                        secondaryButton: .default(Text("Continue"), action: continueTapped)
                    )
                }
jnpdx
  • 45,847
  • 6
  • 64
  • 94
Jon
  • 23
  • 5
  • 1
    I'm not seeing any code here that repeats. Can you show some more of your code? Ideally, a reproducible example? – jnpdx Feb 17 '21 at 22:00
  • Please add a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) or explain your issue better. – pawello2222 Feb 17 '21 at 23:34

1 Answers1

0

I found that the function passed on to the next question. So I answer the first question, press review and after 10 sec it would automatically go to the next question. I found that then this would happen to the next quetsion too, before I pressed anything. I found that adding ' -> Void ' to the code stopped it.

func nextTapped() -> Void {
    DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
        nextQuestion()
    }
}

func continueTapped() {
    nextQuestion()
}
Jon
  • 23
  • 5