【问题标题】:How we call a function in swift3.0swift3.0中我们如何调用函数
【发布时间】:2017-02-16 08:02:40
【问题描述】:
func directionsFromCurrentLocation(to:CLLocationCoordinate2D,directionCompletionHandler:DirectionsCompletionHandler){

此代码在苹果地图中用于在两个目的地之间查找。 而且,我正在使用此代码。

mapManager.directionsFromCurrentLocation(to: destination!) { (route, directionInformation, boundingRegion, error) -> () in

【问题讨论】:

  • 你的问题是?

标签: ios8 swift3 apple-maps


【解决方案1】:

如果您对尾随闭包(函数调用末尾的{ } 分隔代码块)感到困扰,请阅读文档here

简而言之(取自上面的链接):

如果您需要将闭包表达式作为 函数的最终参数和闭包表达式很长,它可以 将其写为尾随闭包会很有用。尾随 闭包写在函数调用的括号之后,即使 它仍然是函数的参数。当你使用尾随 闭包语法,你不要将闭包的参数标签写为 函数调用的一部分。

func someFunctionThatTakesAClosure(closure: () -> Void) {
    // function body goes here
}

// Here's how you call this function without using a trailing closure:
someFunctionThatTakesAClosure(closure: {
    // closure's body goes here
})

// Here's how you call this function with a trailing closure instead:
someFunctionThatTakesAClosure() {
    // trailing closure's body goes here
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 2018-12-06
    • 1970-01-01
    相关资源
    最近更新 更多