Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subclassing MKAnnotation error, conform to Protocol

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
}
}
like image 891
Eric Chuang Avatar asked Jul 23 '26 17:07

Eric Chuang


1 Answers

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.

like image 171
Grimxn Avatar answered Jul 26 '26 08:07

Grimxn