title: Would I need to have an asynchronous function for this while loop?
body: <p>I'm fairly new to swift and programming as a whole, I have some code that will loop through a hardcoded amount which represents posts (this will always stay the same and so I hardcoded it) and run a function with the position of the where currently the while loop has got to which returns a string of an URL of a cached video file downloaded from firebase. Whenever the URL of the 10 posts is returned it gets appended into an array, which, by the end should have be full of 10 strings that are all unique urls to different videos stored on the device:</p>
  
  <pre><code> var fileArray = [String]()
  
   func getPosts(){
      var pos = 0
      let numOfPosts = 10
      while pos &lt;= numOfPosts{
          FeaturedPostsManager.shared.getFeaturedPosts(index: pos, completion: { url in
              if url != nil{
                  self.fileArray.append(url!)
              }else{
                  print("error")
              }
          })
          pos += 1
      }
      performSegue(withIdentifier: "showHome", sender: nil)
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      let recveiverVC = segue.destination as! HomeViewController
      recveiverVC.fileArray = fileArray
  }
  </code></pre>
  
  <p>My problem is it seems as if the <code>performSegue(withIdentifier: "showHome", sender: nil)</code> gets executed before the array has even one url value in it as I can see in the console that the URLs are being retrieved successfully, just that when, in my HomeViewController, my array returns empty. Would I need some sort of asynchronous function here to only allow the <code>performSegue(withIdentifier: "showHome", sender: nil)</code> code execute when the while loop has finished and hence have a full array of urls?</p>
  
  <p>Thanks, </p>
  
  <p>Nathan</p>