4

I have another problem now with MapKit / MKDirections.

After I got everything working fine, Swift 2.0 came out and the 'calculateDirectionsWithCompletionHandler' method that looks like this:

directions.calculateDirectionsWithCompletionHandler({(response:
            MKDirectionsResponse!, error: NSError!) in

            if error != nil {
                println("Error getting directions")
            } else {
                self.showRoute(response)
            }

        })

does not work any more. It's giving me this error on line 1:

'(MKDirectionsResponse!, NSError!) -> Void' is not convertible to 'MKDirectionsHandler' (aka '(Optional<MKDirectionsResponse>, Optional<NSError>) -> ()')

Before the update this worked perfectly fine.... Thank you in advance for your help! :-)

unixb0y
  • 979
  • 1
  • 10
  • 39

1 Answers1

6

For swift 2.0:

let directions = MKDirections(request: request)
directions.calculateDirectionsWithCompletionHandler{
    response, error in

    guard let response = response else {
        //handle the error here
        return
       }
       self.showRoute(response)
    }

For more Info refer THIS.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165