I've looked at other codes and snippets from other stack overflow questions on subclassing. All I'm trying to do is subclass MKAnnotation. I'm using Xcode 6.3. This code works on my friend's but not mine.
I get a Type 'Annotation' does not conform to protocol 'MKAnnotation' error
import Foundation
import MapKit
import UIKit
class Annotation : NSObject, MKAnnotation {
var location: CLLocationCoordinate2D
var title: String
var subtitle: String
init(location: CLLocationCoordinate2D, title: String, subtitle: String) {
self.location = location
self.title = title
self.subtitle = subtitle
}
}
You are not fully conforming to the MKAnnotation protocol. In addition to the title & subtitle properties (which are actually optional), you need to expose a coordinate property (see here).
Your location (which is a CLLocationCoordinate2D) will do the trick if you simply rename it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With