昨晚我升级到了SWIFT1.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
}
}在第3行,我遇到了一些难以理解的错误-- Objective-C method 'setCoordinate:' provided by the setter for 'coordinate' conflicts with the optional requirement method 'setCoordinate' in protocol 'MKAnnotation' --我尝试更改变量名之类的,但是没有帮助。有人知道怎么解决这个问题吗?
这个类用于我的mapview上的注释。
发布于 2015-02-10 10:28:36
如果您不需要在初始化后更改坐标,那么您可以这样使用它。它适用于我与Swift 1.2:
class CustomAnnotation : NSObject, MKAnnotation {
let coordinate: CLLocationCoordinate2D
var title: String
init(coordinate: CLLocationCoordinate2D, title: String) {
self.coordinate = coordinate
self.title = title
}
}发布于 2015-02-14 02:45:49
我也有同样的问题,所以我就这么做了:
private var _coordinate: CLLocationCoordinate2D
var coordinate: CLLocationCoordinate2D {
return _coordinate
}
init(coordinate: CLLocationCoordinate2D) {
self._coordinate = coordinate
super.init()
}
func setCoordinate(newCoordinate: CLLocationCoordinate2D) {
self._coordinate = newCoordinate
}这样,coordinate仍然是只读的,您可以使用setCoordinate方法。
https://stackoverflow.com/questions/28428115
复制相似问题