title: Completing geocoding before segueing to the next scene swift 3/xcode
body: <p>This is a fairly common topic and i've done my research but still just trying to get my head around closure/completion handlers.</p>
  
  <p>I've got a scene where a location is entered. The user hits submit and there's a segue from submit to the next scene. I recognise the geocode is async but I want the geocode to complete in case there is an error before getting to the next scene.</p>
  
  <p>There were a couple of short posts on this site but nothing substantive.</p>
  
  <p>Below is my attempt at a completion handler which fails. I get the alert if there is an error but it first goes to the next scene before the alert pops.</p>
  
  <pre><code>func geocodeAddress (completion: @escaping () -&gt; ()) {
      let geoCoder = CLGeocoder()
      var coords: CLLocationCoordinate2D?
  
      address =  locationData(addressString)
  
      geoCoder.geocodeAddressString((address)!, completionHandler: {(placemarks: [CLPlacemark]?, error: Error?) -&gt; Void in            
          if error != nil {
              self.alertGeocodeError()        
          }        
          if let placemark = placemarks?[0]{
              // Convert the address to a coordinate
              let location = placemark.location
              coords = location!.coordinate
  
              completion()
              self.performSegue(withIdentifier: "locationToConfirmSegue", sender: coords)           
              }    
          })    
      }
  
  override func prepare (for segue: UIStoryboardSegue, sender: Any?){
      geocodeAddress{
          if let destinationVC = segue.destination as? ConfirmController {
              destinationVC.coords = sender as! CLLocationCoordinate2D
          }
       }   
   }
  </code></pre>
  
  <p>I don't quite get the @esaping either and any advice would be great.</p>
  
  <p>Thanks.</p>