I have a custom class that conforms to the MKAnnotation protocol. An instance of this class belongs to the viewController along with an object of type MKMapView called _mapView . I set viewController as a _mapView delegate. In the user class interface, I stated:
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
as required by the MKAnnotation protocol. I also @synthesize in the same class implementation. However, when I send the following message from viewController:
[_mapView addAnnotation:myCustomClass]
I get an error message:
<NSInvalidArgumentException> -[myCustomClass setCoordinate:]: unrecognized selector sent to instance 0x1479e0
If I go to my class implementation file and define
- (void) setCoordinate:(CLLocationCoordinate2D)newCoordinate { coordinate = newCoordinate; }
then the annotation is added to the map successfully.
Should not @synthesize coordinate; take care of the setCoordinate: method setCoordinate: It seems strange that I should both @synthesize coordinate and write the (void) setCoordinate: method.
What am I missing?
Nick
source share