gpt4 book ai didi

ios - Swift 2 reverseGeocodeLocation 错误

转载 作者:行者123 更新时间:2023-11-29 01:38:44 29 4
gpt4 key购买 nike

我是 Swift 开发的新手。我刚刚将现有的工作代码转换为 swift2,同时从 6 更新 Xcode 7。

    private func decodeLocation(array: [AnyObject]!, err: NSError!) -> Void {
if err == nil {
let mark = array.first as! CLPlacemark
country = mark.ISOcountryCode
city = mark.subAdministrativeArea!.stringByReplacingOccurrencesOfString(" ", withString: "", options: NSStringCompareOptions(), range: nil)
region = mark.administrativeArea
coordinates = "\(mark.location!.coordinate.latitude),\(mark.location!.coordinate.longitude)"
print("Country: \(country!)")
print("City: \(city!)")
print("Region: \(region!)")
print("Loc: \(coordinates!)")
delegate?.didGetLocation("\(coordinates!)")
}
}
// Delegates
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse {
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//An array of CLLocation objects. The most recent location update is at the end of the array.

dispatch_once(&geoCoderToken, {
self.currentLocation = locations.last as? CLLocation!
self.geoCoder.reverseGeocodeLocation(self.currentLocation!, completionHandler: self.decodeLocation)
})

}

当我构建时,出现此错误。

Cannot convert value of type '([AnyObject]!, err: NSError!) -> Void' to expected argument type 'CLGeocodeCompletionHandler' (aka '(Optional<Array<CLPlacemark>>, Optional<NSError>) -> ()')

如果您有任何想法,请告诉我。谢谢!

最佳答案

我认为您的完成处理程序上的签名不正确

self.decodeLocation

该方法需要如下所示:

func decodeLocation(array:[CLPlacemark]?, error:NSError?) {
...
}

更新:

您的回调函数似乎仍然没有编译器想要的签名。

decodeLocation(array: [AnyObject]!, err: NSError!) -> Void

不等于

```(Optional>, 可选) -> ()

```

这是我上面发布的速记语法的普通版本。

func decodeLocation(array:Array<CLPlacemark>?, error:<NSError>?) {
...
}

如果你在 github 上有一个 Playground 或一个项目,我可以看看我也许可以提供更多帮助。

关于ios - Swift 2 reverseGeocodeLocation 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32671127/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com