我试图检索一个MKRoute包含多条路线的数组,这些路线都从同一个地方开始,但每条路线都有不同的目的地。
问题是我能想出的唯一方法是通过递归函数,但我找不到任何关于如何使用带有完成块的递归函数的信息。由于加载路由是异步完成的,因此需要一个完成块。
我如何获得以下功能但带有完成块?“添加到退货”功能?
func factorial(of num: Int) -> Int {
if num == 1 {
return 1
} else {
return num * factorial(of:num - 1)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的功能代码
func getDirections(originCoordinate: CLLocationCoordinate2D, destinationCoordinates: [CLLocationCoordinate2D], completion: @escaping(_ routes:[MKRoute]?, _ error: Error?) -> Void) {
// Origin is the same for each route, what changes is the destination
// A singular origin coordinate with an array of destination coordinates is passed in
// The function would in theory be recursive, …Run Code Online (Sandbox Code Playgroud)