Swift 2.0 GeoCoder 参数列表
Swift 2.0 GeoCoder argument list
我花了一天时间将项目转换为 Swift 2.0,我对以下代码片段有什么问题感到困惑,该代码片段旨在在地图上显示地址(以字符串格式提供) .
geocoder.geocodeAddressString(addressString, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if(error != nil) {
println("Error", error)
} else if let placemark = placemarks?[0] as? CLPlacemark {
var placemark:CLPlacemark = placemarks[0] as! CLPlacemark
let coordinates:CLLocationCoordinate2D = placemark.location.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinates, span)
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = coordinates
pointAnnotation.title = locationTitle
pointAnnotation.subtitle = addressString
map.addAnnotation(pointAnnotation)
map.centerCoordinate = coordinates
map.setRegion(region, animated: true)
map.selectAnnotation(pointAnnotation, animated: true)
}
})
这更近了。函数签名已更改,println
现在是 print
:
geocoder.geocodeAddressString(addressString, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
if (error != nil) {
print("Error \(error!)")
} else if let placemark = placemarks?[0] {
let coordinates:CLLocationCoordinate2D = placemark.location.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinates, span)
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = coordinates
pointAnnotation.title = locationTitle
pointAnnotation.subtitle = addressString
map.addAnnotation(pointAnnotation)
map.centerCoordinate = coordinates
map.setRegion(region, animated: true)
map.selectAnnotation(pointAnnotation, animated: true)
}
})
我花了一天时间将项目转换为 Swift 2.0,我对以下代码片段有什么问题感到困惑,该代码片段旨在在地图上显示地址(以字符串格式提供) .
geocoder.geocodeAddressString(addressString, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if(error != nil) {
println("Error", error)
} else if let placemark = placemarks?[0] as? CLPlacemark {
var placemark:CLPlacemark = placemarks[0] as! CLPlacemark
let coordinates:CLLocationCoordinate2D = placemark.location.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinates, span)
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = coordinates
pointAnnotation.title = locationTitle
pointAnnotation.subtitle = addressString
map.addAnnotation(pointAnnotation)
map.centerCoordinate = coordinates
map.setRegion(region, animated: true)
map.selectAnnotation(pointAnnotation, animated: true)
}
})
这更近了。函数签名已更改,println
现在是 print
:
geocoder.geocodeAddressString(addressString, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
if (error != nil) {
print("Error \(error!)")
} else if let placemark = placemarks?[0] {
let coordinates:CLLocationCoordinate2D = placemark.location.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinates, span)
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = coordinates
pointAnnotation.title = locationTitle
pointAnnotation.subtitle = addressString
map.addAnnotation(pointAnnotation)
map.centerCoordinate = coordinates
map.setRegion(region, animated: true)
map.selectAnnotation(pointAnnotation, animated: true)
}
})