MKAnnotation and setCoordinate:

Viewed 3251

I have a custom class that conforms to the MKAnnotation protocol. An instance of this class is held by a viewController, along with an object of type MKMapView, called _mapView. I've set the viewController to be _mapView's delegate. In the custom class interface I've declared:

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

as it's required per the MKAnnotation protocol. I also @synthesize it in that same class's implementation. However when I send the following message from the viewController:

[_mapView addAnnotation:myCustomClass];

I get an error:

<NSInvalidArgumentException> -[myCustomClass setCoordinate:]: unrecognized selector sent to instance 0x1479e0

If I go into my custom Class's implementation file and define

- (void) setCoordinate:(CLLocationCoordinate2D)newCoordinate
{
    coordinate = newCoordinate;
}

then the annotation is added to the map successfully.

Shouldn't @synthesize coordinate; take care of the setCoordinate: method? It seems odd that I have to both @synthesize the coordinate as well as write the (void) setCoordinate: method.

What am I missing?

1 Answers
Related