On 9 Nov 2010, at 3:31 AM, Dan Hopwood wrote:

> Ok so I am working with MKAnnotations on my map view and want to know the *
> correct* (i.e. the Apple intended) way to set up my custom annotation class
> so that I can set the coordinate upon initialisation but also access the
> coordinate attribute from outside the class e.g. in my case I wish to do
> something like:
> 
> region.center = myAnnotation.coordinate;
> 
> The above gives me an error and says the assignment is between incompatible
> types.

We need something better than "something like." Assuming "region" is an 
MKCoordinateRegion, and "myAnnotation" implements MKAnnotation, the above line 
is okay. But if "region" is your shorthand for "someMapView.region", you have a 
problem. Show us the code.

> I've done plenty of googling and have seen a few different solutions but
> none of which seemed to allow me to access the coordinate. Some people
> define a coordinate member variable and then @property/synthesize.
> Others named the member variable _coordinate and then *just* synthesized it
> (not @property) using @synthesize _coordinate = coordinate; - I don't fully
> understand what that means. Finally (in the case of the MapCallouts source)
> others have defined a function called coordinate that returns the
> coordinate.

<MKAnnotation> already declares @property coordinate, so there is no reason to 
re-declare it. A -coordinate method, or a @synthesize if there is a 
"coordinate" instance variable to back it, is enough.

> If someone could give tell me the correct solution by means of a really
> simple example i.e. what should go in the .h and .m (I'm only interested in
> the coordinate attribute for now) and then how to correctly access the
> coordinate attribute from outside the class for assignment e.g. the center
> attribute of the region object (sorry I can't remember the exact name).

Don't do this by Braille from what I can tell you off the top of my head, or 
from cookbook examples. Read and understand for yourself the documentation on 
properties at 
<http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html>.

        — F

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to