我收到此错误:
无法将类型'(_,_)->()'的值转换为预期的参数类型'(Route ?, Error?)'
这是我的代码:
@objc func actionWithoutParam(){
calculateRoute(from: (MapView.userLocation!.coordinate), to: location) { (route, error) in
if error != nil{
print("Error")
}
}
}
这是计算路线方法:
func calculateRoute(from originCoor: CLLocationCoordinate2D, to destinationCoor: CLLocationCoordinate2D, completion: (Route?, Error?) ) -> Void{
}
答案 0 :(得分:1)
您写的封尾是错误的,请使用此
// function creation
func calculateRoute(from originCorr: CLLocationCoordinate2D, to destinationCorr: CLLocationCoordinate2D, completion: (Route?, Error?) -> Void) {
}
// function calling
calculateRoute(from: .init(), to: .init()) { (route, error) in
}
答案 1 :(得分:0)
问题是calculateRoute
中闭包参数缺少返回类型,请将闭包的定义更改为
(String?, Error?) -> Void