Swift 2.0 GeoCoder argument list

929 views Asked by At

Having spent the day converting a project to Swift 2.0, I have am stumped on what is wrong with the following code snippet, which is intended to show an address (supplied in string format) on a map.

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)
    }
})
1

There are 1 answers

0
vacawama On BEST ANSWER

This is a lot closer. The function signature has changed, println is now 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)
    }
})