Reputation: 704
I wanted to jump over to use Xcode 7.3.1 and convert my code, but I'm facing some kind of problem here, this is how I used to use it in Swift 1.1 but I am getting error:
Cannot convert value of type '([AnyObject]!, NSError!) -> Void' to expect argument type 'CLGeocodeCompletionHandler' (aka '(Optional>, Optional)-> ()'):
Here is my code:
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)")
}
}
})
}
Upvotes: 1
Views: 1641
Reputation: 12023
As said in the error message, CLGeocodeCompletionHandler
returns optional not a concrete object so just change the completionHandler code to
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
})
Upvotes: 1