【发布时间】:2016-07-11 08:02:29
【问题描述】:
我想跳过去使用 Xcode 7.3.1 并转换我的代码,但我在这里遇到了一些问题,这就是我过去在 Swift 1.1 中使用它的方式,但我遇到了错误:
无法将类型“([AnyObject]!,NSError!)-> Void”的值转换为期望参数类型“CLGeocodeCompletionHandler”(又名“(可选>,可选)->()”):
这是我的代码:
private func geoCodeAddress(address:NSString){
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address as String, completionHandler: {(place marks: [AnyObject]!, error: NSError!) -> Void in ---> Error //Cannot convert value of type '([AnyObject]!, NSError!) -> Void' to expect argument type 'CLGeocodeCompletionHandler' (aka '(Optional<Array<CLPlacemark>>, Optional<NSError>)-> ()')
if (error != nil) {
self.geocodingCompletionHandler!(gecodeInfo:nil,placemark:nil,error: error.localizedDescription)
}
else{
if let placemark = placemarks?[0] as? CLPlacemark {
var address = AddressParser()
address.parseAppleLocationData(placemark)
let addressDict = address.getAddressDictionary()
self.geocodingCompletionHandler!(gecodeInfo: addressDict,placemark:placemark,error: nil)
}
else {
self.geocodingCompletionHandler!(gecodeInfo: nil,placemark:nil,error: "invalid address: \(address)")
}
}
})
}
【问题讨论】:
标签: ios swift swift2 core-location