MKDirections / calculateDirectionsWithCompletionHandler no longer works in Swift 2.0

I have one more problem with MapKit / MKDirections.

After everything worked well, Swift 2.0 appeared, and 'calculateDirectionsWithCompletionHandler', which 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. This gives me this error on line 1:

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

Before the update, this worked fine. Thanks in advance for your help! :-)

+4
source share
1 answer

For quick 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 information see IT .

+6
source

Source: https://habr.com/ru/post/1609512/


All Articles