title: Swift how to make a function execute after another function completed
body: <p>I wrote two Swift functions (just a multiple choice quiz app)</p>
  
  <pre><code>func createQuestions() // this goes to Parse, and fetches the questions data that are going to question the users and store them into local arrays
  
  func newQuestion() // this also fetches some other data (for example, some incorrect choices) from Parse and read local variables and finally set the labels to correctly display to the users
  </code></pre>
  
  <p>I want in <code>ViewDidLoad</code>, first execute <code>createQuestion()</code>, after it is fully completed then run <code>newQuestion()</code>. Otherwise the <code>newQuestion()</code> has some issues when reading from local variables that were supposed to be fetched. How am I going to manage that?</p>
  
  <p>EDIT: I learned to use closure! One more follow up question. I am using a for loop to create questions. However, the problem is that the for loop does not execute orderly. Then my check for repeated function (vocabTestedIndices) fails and it would bring two identical questions. I want the for loop to execute one by one, so the questions created will not be overlapped.
  <a href="https://i.stack.imgur.com/3a3Kx.png" rel="nofollow noreferrer">code image</a></p>