title: RXSwift flatmap that returns from an async completion handler
body: <p>I am trying to create a searchBar that searches for addresses via a MKLocalSearch with request and using RXSwift and binding to RXCocoa</p>
  
  <p>So far i have done the following
  1. filter and debounce to avoid too many requests:</p>
  
  <pre><code>let searchRes = searchBar.rx.text
      .orEmpty
      .filter { query in
          return query.characters.count &gt; 4
      }
      .debounce(1, scheduler: MainScheduler.instance)
  </code></pre>
  
  <ol start="2">
  <li><p>the resulting String query is map:ed to create a MKLocationSearch and then flatMapp:ed to return an array of MKMapItems to be able to bind the array to tableView's items:</p>
  
  <pre><code>searchRes.map{query -&gt; MKLocalSearch in
      let request = MKLocalSearchRequest()
      request.naturalLanguageQuery = query
      request.region = self.mapView.region
      return MKLocalSearch(request: request)
  }.flatMapLatest{search -&gt; Observable&lt;[MKMapItem]&gt; in
      search.start(completionHandler:{(response, error) in
          let items: Variable&lt;[MKMapItem]&gt; = Variable([])
          if let resp = response {
              //need to return the result form this
              // i.e. items.value = response.mapItems
          }
          //can not return from here since the request is async
      }
  }.bindTo //continue to bind to tableview
  </code></pre></li>
  </ol>
  
  <p>How can this be done using RXSwift, i could not find any relevant example </p>