title: How do I update the UI on a background thread in Swift?
body: <p>Hi im new to swift and I to want run a function in the background, my problem is that once the function is running the hole app freezes I can't use the interface until the function end.</p>
  
  <p><code>StartStream</code> is a button that will call the function <code>self.StreamCam</code> for streaming the camera and then it will move the current view to <code>CAMView</code> to see the camera interface.</p>
  
  <p>here's what I used to call the the function :</p>
  
  <pre><code>@IBAction func StartStream(sender: UIButton) {
  
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
     let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
  
     let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("CAMView") as! CAM
  
     let seconds = 2.0
     let delay = seconds * Double(NSEC_PER_SEC)
     let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
  
     dispatch_after(dispatchTime, dispatch_get_main_queue(), {
          self.StreamCam(self.session)
     })
  
     dispatch_async(dispatch_get_main_queue(), {
         self.presentViewController(nextViewController, animated:true, completion:nil)});
     });
  
  }
  </code></pre>
  
  <p>Any suggestions?</p>