swiftmapkitmkmapitemclplacemark

'MKMapItem' is not convertible to 'CLPlacemark'


How can I convert MKMapItem to CLPlacemark in Swift?

My code gives me a compiler error 'MKMapItem' is not convertible to 'CLPlacemark':

var mapItems:[MKMapItem] = []
let mi = self.mapItems[indexPath.row];
ann.placemark = mi as CLPlacemark

In ObjC I just did ann.placemark = (CLPlacemark *)mi;


Solution

  • MKMapItem is not a subclass of CLPlacemark. I'm not that familiar with MapKit, so maybe it was indeed possible to directly cast a MKMapItem to a CLPlacemark without problem.

    MKMapItem does have a property called placemark with type MKPlacemark though. MKPlacemark is a subclass of CLPlacemark and can be used as such.