Aditya Shinde Aditya Shinde - 3 months ago 34
iOS Question

Unable to conform MKAnnotation protocol in Swift

When I try to conform

MKAnnotation
protocol it throw error my class does not conform to protocol
MKAnnotation
. I am using the following code

import MapKit
import Foundation

class MyAnnotation: NSObject, MKAnnotation
{

}


The same thing is possible with Objective-C.

Answer

You need to implement following required property in the calls:

class MyAnnotation: NSObject, MKAnnotation {
    var myCoordinate: CLLocationCoordinate2D

    init(myCoordinate: CLLocationCoordinate2D) {
        self.myCoordinate = myCoordinate
    }

    var coordinate: CLLocationCoordinate2D { 
        return myCoordinate
    }
}
Comments