title: Wait For Asynchronous Operation To Complete in Swift
body: <p>I am not sure how to handle this situation as I am very new to iOS development and Swift. I am performing data fetching like so:</p>
  
  <pre><code>func application(application: UIApplication!, performFetchWithCompletionHandler completionHandler: ((UIBackgroundFetchResult) -&gt; Void)!)
  {
      loadShows()
      completionHandler(UIBackgroundFetchResult.NewData)
      println("Background Fetch Complete")
  }
  </code></pre>
  
  <p>My loadShows() function parses a bunch of data it gets from a website loaded into a UIWebView. The problem is that I have a timer that waits for 10 seconds or so in the loadShows function. This allows for the javascript in the page to fully load before I start parsing the data. My problem is that the completion handler completes before my loadShows() does. </p>
  
  <p>What I would like to do is add a bool for "isCompletedParsingShows" and make the completionHandler line wait to complete until that bool is true. What is the best way to handle this?</p>