Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKAnnotation subclass issues

I upgraded to Swift 1.2 last night, and I got a bug I really can't figure out. The below code worked fine in the previous version of Xcode and 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
    }
}

On line 3, I get the somewhat hard to understand error Objective-C method 'setCoordinate:' provided by the setter for 'coordinate' conflicts with the optional requirement method 'setCoordinate' in protocol 'MKAnnotation' I tried changing variable names and such, but no help. Does anyone have any idea how to fix this?

The class is for annotations on my mapview.

like image 590
Oscar Apeland Avatar asked Feb 10 '23 23:02

Oscar Apeland


1 Answers

If you do not require to change coordinates after initialization then you can use it that way. It works for me with Swift 1.2:

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

    init(coordinate: CLLocationCoordinate2D, title: String) {
        self.coordinate = coordinate
        self.title = title
    }
}
like image 145
Wojciech Rutkowski Avatar answered Feb 13 '23 20:02

Wojciech Rutkowski