子类化MKAnnotation错误,遵循协议

3

我看了其他代码以及其他stackoverflow问题上的片段,都是有关于子类化的。我只是想子类化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
}
}
1个回答

3
您没有完全符合 MKAnnotation 协议。除了 titlesubtitle 属性(实际上是可选的),您还需要公开一个 coordinate 属性(请参见 此处)。
如果您只是重命名,您的 location(它是一个 CLLocationCoordinate2D)就可以解决问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接