samad5353
samad5353

Reputation: 411

Map view Annotation Delegates for swift 3.0

// MARK: - MapView Delegate
override func mapView(_ mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    var anView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationReuseId)

    if anView == nil {
        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationReuseId)
    } else {
        anView!.annotation = annotation
    }
    anView!.image = UIImage(named: "Contactus_gatePin")
    anView?.frame = CGRect(x: 0, y: 0, width: 53, height: 53)
    anView!.backgroundColor = UIColor.clear
    anView!.canShowCallout = false
    return anView
}

override func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    return
}

I am getting error for this method in Swift3. It was working in Swift2.2 i couldn't convert this to Swift 3.0
Please help

Upvotes: 4

Views: 1158

Answers (2)

ronak patel
ronak patel

Reputation: 400

annotation method in swift 3.0

 optional func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    }

Upvotes: 0

Nirav D
Nirav D

Reputation: 72410

In Swift 3 viewForAnnotation method of MKMapViewDelegate is changed like this.

optional func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

}

Fore other methods check Apple Documentation on MKMapViewDelegate.

Upvotes: 3

Related Questions