gpt4 book ai didi

xcode - geocoder.geocodeAddressString 今天不再适用于快速更新

转载 作者:搜寻专家 更新时间:2023-10-31 08:09:48 25 4
gpt4 key购买 nike

https://developer.apple.com/library/prerelease/mac/releasenotes/General/APIDiffsMacOSX10_11/Swift/CoreLocation.html

显示有一些变化

func geocodeAddressString(_ addressString: String!, completionHandler completionHandler: CLGeocodeCompletionHandler!)

到:

func geocodeAddressString(_ addressString: String, completionHandler completionHandler: CLGeocodeCompletionHandler)

我的代码是:

var geocoder = CLGeocoder()

geocoder.geocodeAddressString("\(event!.street), \(event!.city), \(event!.country)", completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if let placemark = placemarks?[0] as? CLPlacemark {
self.event!.lat = placemark.location!.coordinate.latitude
self.event!.long = placemark.location!.coordinate.longitude

self.event!.getMiles(self.currentLocation!.location!.coordinate.latitude, clong: self.currentLocation!.location!.coordinate.longitude)
var mile = self.event!.miles != nil ? NSString(format: "%.1f miles", self.event!.miles!) : "Location services off"
self.milesButton.setTitle(mile as String, forState: .Normal)
}
})

尝试过:

var geocoder = CLGeocoder()
let address = "\(event!.street), \(event!.city), \(event!.country)"
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]) in
let placemark = placemarks[0]
self.event!.lat = placemark.location!.coordinate.latitude
self.event!.long = placemark.location!.coordinate.longitude
self.event!.getMiles(self.currentLocation!.location!.coordinate.latitude, clong: self.currentLocation!.location!.coordinate.longitude)
var mile = self.event!.miles != nil ? NSString(format: "%.1f miles", self.event!.miles!) : "Location services off"
self.milesButton.setTitle(mile as String, forState: .Normal)
})

它只是一直说不允许。尝试了几种不同的组合。这是对 xcode/swift 的最新更新所做的

提前致谢

最佳答案

在 Swift 2 中:

geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in

})

在 Swift 3 中,将 NSError? 替换为 Error?:

geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: Error?) -> Void in

})

或者,更简单,让它为您推断正确的类型:

geocoder.geocodeAddressString(address) { placemarks, error in

}

关于xcode - geocoder.geocodeAddressString 今天不再适用于快速更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32655247/

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