ios – Swift 3.0:无法推断当前上下文中的闭包类型PromiseKit

ios – Swift 3.0:无法推断当前上下文中的闭包类型PromiseKit,第1张

概述我在 swift 3.0中有以下代码,我在哪里使用PromiseKit. func calculateTravelTime(from: CLLocation, to: CLLocation) -> Promise<Double> { Promise<Double> { completion, reject -> Void in let request = MKDirect 我在 swift 3.0中有以下代码,我在哪里使用PromiseKit.

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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067122.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存