title: Firebase asynchronous query
body: <p>I've just started my journey with Firebase and I am pretty new when it comes to Swift.</p>
  
  <p>I am trying to query a data from the Firebase server</p>
  
  <pre><code>func getResults() -&gt; [String] {
      let queryRef = ref.childByAppendingPath("objects")
      var results = [String]()
      queryRef.queryOrderedByChild("name").observeEventType(.ChildAdded, withBlock: { (snapshot) in
          if let number = snapshot.value["number"] as? String {
              results.append(number)
          }
      })
      return results
  }
  </code></pre>
  
  <p>I know the querying works asynchronously, but is there a way to actually tell the function to wait for the results and then return them?</p>
  
  <p>EDIT:</p>
  
  <p>Completed function: </p>
  
  <pre><code>func getResults(completion: ((objects: [String] -&gt; Void)) {
      let queryRef = ref.childByAppendingPath("objects")
      var results = [String]()
      queryRef.queryOrderedByChild("name").observeEventType(.ChildAdded, withBlock: { (snapshot) in
          if let number = snapshot.value["number"] as? String {
              results.append(number)
          }
          if results.count == Int(snapshot.childrenCount) {
          completion(objects: results)
          }
      })
  }
  </code></pre>