title: Where to place countdown timer code?
body: <p>I'm developing an iOS quiz app and every time a question is asked I want a countdown timer of 15 seconds to start. If the user doesn't answer the question by the time the counter hits zero the answer is considered wrong. My question is where would I place the countdown timer code to make sure everytime a question is asked it gives the user 15 seconds to answer? I also want this time to reset every time a new question is asked.</p>
  
  <p>My code:</p>
  
  <pre><code>class ViewController: UIViewController {
      //countdown timer
      @IBOutlet weak var questionTimer: UILabel!
  
      func randomQuestion() {
          //random question
          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)
  
          //create button
          var button:UIButton = UIButton()
  
          //variables
          var x = 1
          rightAnswerBox = arc4random_uniform(4)+1
  
          for index in 1...4
          {
              button = view.viewWithTag(index) as! UIButton
  
              if (index == Int(rightAnswerBox))
              {
                  button.setTitle(choices[0], for: .normal)
              }
              else {
                  button.setTitle(choices[x], for: .normal)
                  x += 1
              }
  
              randomImage()
  
          }
      }
  
      let QADictionary = ["Who is Thor's brother?" : ["Atum", "Loki", "Red Norvell", "Kevin Masterson"], "What is the name of Thor's hammer?" : ["Mjolinr", "Uru", "Stormbreaker", "Thundara"], "Who is the father of Thor?" : ["Odin", "Sif", "Heimdall", "Balder"]]
  
      //wrong view segue
      func wrongSeg() {
         performSegue(withIdentifier: "wrongViewSegue", sender: self)
      }
  
      //proceed screen
      func rightSeg() {
          performSegue(withIdentifier: "rightSeg", sender: self)
      }
  
      //variables
      var rightAnswerBox:UInt32 = 0
      var index = 0
  
      //Question Label
      @IBOutlet weak var questionLabel: UILabel!
  
      //Answer Button
      @IBAction func buttonAction(_ sender: AnyObject) {
          if (sender.tag == Int(rightAnswerBox))
          {
              print ("Correct!")
          }
          else if (sender.tag != Int(rightAnswerBox)) {
              wrongSeg()
              print ("Wrong!")
              questionList = []
          }
  
          randomQuestion()
      }
  
      override func viewDidAppear(_ animated: Bool)
      {
          randomQuestion()
      }
  
      //variables
      var seconds = 15
      var timer = Timer()
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  </code></pre>