func calculateTravelTime(from: CLLocation,to: CLLocation) -> Promise<Double> { Promise<Double> { completion,reject -> VoID in let request = MKDirections.Request() request.transportType = .walking let fromPlacemark = MKPlacemark(coordinate: from.coordinate) let toplacemark = MKPlacemark(coordinate: to.coordinate) let fromMapPoint = MKMAPItem(placemark: fromPlacemark) let toMapPoint = MKMAPItem(placemark: toplacemark) request.source = fromMapPoint request.destination = toMapPoint request.requestsAlternateRoutes = false let directions = MKDirections(request: request) directions.calculate { response,error in if error != nil { reject(error!) } else { let time = (response?.routes.first?.expectedTravelTime ?? 0) / 60.0 completion(time) } } }}
错误代码行:
Promise<Double> { completion,reject -> VoID in
我无法确定它为什么会出现此错误.有没有快速的专家可以帮助我.
谢谢!
解决方法 在目前的PromiseKit版本中无极< T> {履行,拒绝 – >无效}
改为
无极< T> {seal – >无效}
所以,你的新实现将改为这个,
func calculateTravelTime(from: CLLocation,to: CLLocation) -> Promise<Double> { Promise<Double> { seal -> VoID in let request = MKDirections.Request() request.transportType = .walking let fromPlacemark = MKPlacemark(coordinate: from.coordinate) let toplacemark = MKPlacemark(coordinate: to.coordinate) let fromMapPoint = MKMAPItem(placemark: fromPlacemark) let toMapPoint = MKMAPItem(placemark: toplacemark) request.source = fromMapPoint request.destination = toMapPoint request.requestsAlternateRoutes = false let directions = MKDirections(request: request) directions.calculate { response,error in if error != nil { seal.reject(error!) } else { let time = (response?.routes.first?.expectedTravelTime ?? 0) / 60.0 seal.fulfill(time) } } }}总结
以上是内存溢出为你收集整理的ios – Swift 3.0:无法推断当前上下文中的闭包类型PromiseKit全部内容,希望文章能够帮你解决ios – Swift 3.0:无法推断当前上下文中的闭包类型PromiseKit所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)