Re: MKAnnotation coordinate
Re: MKAnnotation coordinate
- Subject: Re: MKAnnotation coordinate
- From: Dan Hopwood <email@hidden>
- Date: Tue, 9 Nov 2010 16:22:49 +0000
Thanks Fritz, a resource like that was what I was looking for - where I can
I will always read Apple's documentation over examples/tutorials since they
are often wrong or inaccurate. I will have a read tonight and see how I get
on.
Sorry I wasn't more specific, I couldn't remember the name of the type - in
the example I gave, region is indeed of type MKCoordinateRegion and
myAnnotation extends NSObject and implements the MKAnnotation protocol
i.e. @interface myAnnotation : NSObject<MKAnnotation>
>From your comments I already understand it better - I thought the instance
variable was also declared, not just the property. Therefore I will declare
coordinate in the header, I won't declare a property and I will synthesize
in the implementation.
-Dan
On 9 November 2010 15:18, Fritz Anderson <email@hidden> wrote:
> 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 (email@hidden)
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:
This email sent to email@hidden