子类化MKAnnotation错误,符合Protocol

时间:2015-04-21 06:17:31

标签: ios swift mkannotation

我查看了子类化中其他堆栈溢出问题的其他代码和片段。我试图做的只是子类MKAnnotation。我正在使用Xcode 6.3。这段代码适用于我的朋友但不是我的。

我收到 类型'注释'不符合协议' 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 个答案:

答案 0 :(得分:3)

您并未完全符合MKAnnotation协议。除了title& subtitle属性(实际上是可选的),您需要公开coordinate属性(请参阅here)。

如果您只是重命名,那么locationCLLocationCoordinate2D)将会成功。