CLGeocodeCompletionHandler ios swift3
有人知道swift3上有什么变化吗?如何修复以下代码 我用的是geocock字符串CLGeocodeCompletionHandler ios swift3,swift3,clgeocoder,Swift3,Clgeocoder,有人知道swift3上有什么变化吗?如何修复以下代码 我用的是geocock字符串 class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?) { let geocoder = CLGeocoder() geocoder.geocodeAddressString(address!, completio
class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?)
{
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address!, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
if let validPlacemark = placemarks?[0]{
print(validPlacemark.location?.coordinate)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: (validPlacemark.location?.coordinate)!, span: span)
locationMap?.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = (validPlacemark.location?.coordinate)!
annotation.title = title
annotation.subtitle = subtitle
locationMap?.addAnnotation(annotation)
}
} as! CLGeocodeCompletionHandler)
}
这一行出现错误..这一行就崩溃了as!CLGeocodeCompletionHandler)
显示
时没有错误,请使用以下代码,即删除[CLPlacemark]?还有N错误?来自完成处理程序
class func getMapByAddress(_ locationMap:MKMapView?, address:String?, title: String?, subtitle: String?)
{
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address!, completionHandler: {(placemarks, error) -> Void in
if let validPlacemark = placemarks?[0]{
print(validPlacemark.location?.coordinate)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: (validPlacemark.location?.coordinate)!, span: span)
locationMap?.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = (validPlacemark.location?.coordinate)!
annotation.title = title
annotation.subtitle = subtitle
locationMap?.addAnnotation(annotation)
}
})
}
注释代码,然后开始重写代码,让Xcode的autosuggest引导您使用新语法。