【问题标题】:MKDirections / calculateDirectionsWithCompletionHandler not working anymore in Swift 2.0MKDirections / calculateDirectionsWithCompletionHandler 在 Swift 2.0 中不再工作
【发布时间】:2015-09-29 16:43:32
【问题描述】:

我现在在使用 MapKit / MKDirections 时遇到了另一个问题。

在我一切正常之后,Swift 2.0 出来了, 'calculateDirectionsWithCompletionHandler' 方法如下所示:

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

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

        })

不再起作用了。 它在第 1 行给了我这个错误:

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

在更新之前,这工作得非常好...... 预先感谢您的帮助! :-)

【问题讨论】:

  • 问题解决了吗?
  • 以下解决方案不起作用? @QadirHussain

标签: swift swift2 ios9 xcode7 directions


【解决方案1】:

对于 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)
    }

更多信息请参考THIS

【讨论】:

  • 太棒了!非常感谢! :-)
  • 对不起,我会投票,但我没有足够的声誉:/这非常好:) ??。这是新的,这种语法,对吧?
  • 谢谢??。这很简单^^
  • 太棒了!!编码愉快。
猜你喜欢
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多