2017-02-16 4 views
-3
func directionsFromCurrentLocation(to:CLLocationCoordinate2D,directionCompletionHandler:DirectionsCompletionHandler){ 

이 코드는 두 목적지 사이를 찾기 위해 Apple지도에서 사용됩니다. 그리고이 코드를 사용하고 있습니다. 당신이 후행 폐쇄 (함수 호출의 끝에 코드의 { } 구분 된 덩어리)에 의해 방해하는 경우swift3.0에서 함수를 호출하는 방법

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

그리고 귀하의 질문은 무엇입니까? – Sweeper

답변

0

워드 프로세서 here을 참조하십시오. (위의 링크에서 촬영) 한마디로

:

당신이 a를 함수의 마지막 인수로 기능과 폐쇄 표현이 긴, 그것은 에 유용 할 수 있습니다에 폐쇄 식을 통과해야하는 경우 대신 후행 클로저로 작성하십시오. 후행 클로저는 함수 호출의 괄호 뒤에 작성됩니다 ( ). 여전히 함수에 대한 인수입니다. 후행 클로저 구문을 사용하는 경우 클로저의 인수 레이블을 함수 호출의 일부로 쓰지 마십시오.

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 
}