子类化 MKAnnotation 错误,符合协议

subclassing MKAnnotation error, conform to Protocol

我查看了有关子类化的其他堆栈溢出问题的其他代码和片段。我想要做的就是子类化 MKAnnotation。我正在使用 Xcode 6.3。此代码适用于我朋友的,但不适用于我的。

我得到一个 Type 'Annotation' does not conform to protocol 'MKAnnotation' 错误

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
}
}

您没有完全遵守 MKAnnotation 协议。除了 titlesubtitle 属性(实际上是可选的)之外,您还需要公开一个 coordinate 属性(参见 here)。

您的 location(即 CLLocationCoordinate2D)只需重命名即可。