title: Returning value from asynchronous function from within synchronous function in Swift
body: <p>I understand that this has been asked before, but the answers provided have simply not answered my question.</p>
  
  <p>I have this synchronous function, numberOfRowsInSection for a UITableView:</p>
  
  <pre><code>func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      var returnValue = 0
      self.getFavorites() { result in
          returnValue = result.count
      }
      return returnValue
  }
  </code></pre>
  
  <p>and this is the getFavorites() function:</p>
  
  <pre><code>func getFavorites(completionHandler: (([NSString])-&gt;())){
      let setter = self.xpcConnection?.remoteObjectProxy as FavoritesProtocol
      setter.getFavorites({(reply) -&gt; Void in
          if var unwrappedReply = reply {
              completionHandler(unwrappedReply)
          }
      })
  }
  </code></pre>
  
  <p>Right now the numberOfRowsInSection function returns 0 because the function returns before the async function completes. I understand this concept.</p>
  
  <p>What doesn't help me about the answers that I've found so far is that none of them really say how you can return the value you pass back in with your completionHandler, they all have really easy examples like:</p>
  
  <pre><code>func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      self.getFavorites() { result in
          println("Result count: " \(result.count)")
      }
  }
  </code></pre>
  
  <p>That's great, if all you're doing is printing the value, but I need to return the value! </p>
  
  <p>Thanks in advance</p>