I’ve gotten to a point where I’m starting to think this is may actually be a bug in Xcode, but to be sure, I’m asking it here. I was working on my app that uses MapKit and CoreLocation, but at some point I started getting the warning “Property ‘coordinate’ requires method ‘-coordinate'”. At first I thought I was doing something wrong, as I did use the property coordinate for an MKPointAnnotation, but after I commented that out, the warning remained.
In fact, after I’ve commented out pretty much everything, I still get the warning. It tells me the file name and line number (the line with @end), but if I search for coordinate in that file, there aren’t any results. The .h doesn’t declare the property either, so I’m really lost as to where this error is coming from… I can provide you with code, of course, but I’ve commented so much stuff out that it doesn’t really make any sense to post it here. Just a few memory management methods without any actual content other than sending a message to super…
Xcode is correct in telling you that you’re required to implement -coordinate. This is a non-optional method of the MKAnnotation protocol.
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html
I believe the reason you can’t synthesize coordinate is not because you didn’t declare the property, but because you haven’t told the compiler what storage to use.
Adding
to the fields (variables) section of your class interface will give the compiler the storage it is looking for.
Or you can point the compiler to other storage using this syntax:
But none of that really matters, because you don’t have to use synthesize.
Just implement the method yourself! The required part is readOnly so you only need to implement the getter.
@property and @synthesize are primarily shortcuts. @synthesize just says to the compiler – “Implement these accessors if I haven’t”. But normally you declare a property like this, right?
and then you synthesize it. @synthesize creates the appropriate implementations for the declarations implied by @property:
and uses the storage you provided when you declared the instance variable, NSString *someString.
Incidentally, in Xcode 4 @synthesize automatically creates storage for you if it doesn’t already exist.