MKAnnotation子类问题

Osc*_*and 4 xcode mapkit mkannotation ios swift

我昨晚升级到Swift 1.2,我得到了一个我真想不通的bug.以下代码在之前版本的Xcode和Swift中运行良好.

//MARK: Annotation Object
class PointAnnotation : NSObject, MKAnnotation {
    var coordinate: CLLocationCoordinate2D
    var title: String
    var subtitle: String
    var point: Point
    var image: UIImage
    var md: String

    init(point: Point) {
        self.coordinate = point.coordinate
        self.title = point.title
        self.subtitle = point.teaser
        self.image = UIImage(named: "annotation.png")!
        self.point = point
        self.md = point.content
    }
}
Run Code Online (Sandbox Code Playgroud)

在第3行,我得到了一些有点难以理解的错误 Objective-C method 'setCoordinate:' provided by the setter for 'coordinate' conflicts with the optional requirement method 'setCoordinate' in protocol 'MKAnnotation'我尝试更改变量名称等,但没有帮助.有谁知道如何解决这个问题?

该课程用于我的mapview上的注释.

Woj*_*ski 8

如果您在初始化后不需要更改坐标,那么您可以这样使用它.它适用于Swift 1.2:

class CustomAnnotation : NSObject, MKAnnotation {
    let coordinate: CLLocationCoordinate2D
    var title: String

    init(coordinate: CLLocationCoordinate2D, title: String) {
        self.coordinate = coordinate
        self.title = title
    }
}
Run Code Online (Sandbox Code Playgroud)