title: Store data in MKAnnotation?
body: <p>So I'm pretty new to Xcode and Objective-C. I have several ArtPiece objects with various attributes stored in an array. I then add them as MKAnnotations to the mapview. What I need to be able to do is send a reference to the array position they came from on click. I believe MKAnnotations only have the data members title, image, and location, so when I make an MKAnnotation from the objects, the annotation does not keep any of the other attributes. So, my question is, how can I manage to keep a reference to the array position of the object the annotation was created from so that I can send it to other methods so they can retrieve the additional information about the object from the array for detail views etc.  Is there any way to store a single int value in an annotation? I don't think there is so any other ideas?</p>
  
  <p>Here is my ArtPiece.h:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;MapKit/MapKit.h&gt;
  @interface ArtPiece : NSObject &lt;MKAnnotation&gt;{
  
      NSString *title;
      NSString *artist;
      NSString *series;
      NSString *description;
      NSString *location;
      NSString *area;
      NSNumber *latitude;
      NSNumber *longitude;
      UIImage *image;
  }
  
  @property (nonatomic, retain) NSString *title;
  @property (nonatomic, retain) NSString *artist;
  @property (nonatomic, retain) NSString *series;
  @property (nonatomic, retain) NSString *description;
  @property (nonatomic, retain) NSString *location;
  @property (nonatomic, retain) NSString *area;
  @property (nonatomic, retain) NSNumber *latitude;
  @property (nonatomic, retain) NSNumber *longitude;
  @property (nonatomic, retain) UIImage *image;
  
  
  @end
  </code></pre>
  
  <p>and here is the .m:</p>
  
  <pre><code>#import "ArtPiece.h"
  #import "FindArtController.h"
  #import "ArtPiece.h"
  #import &lt;MapKit/MapKit.h&gt;
  
  @implementation ArtPiece
  
  - (NSString *)description{
      return [NSString stringWithFormat:@"title: %@",title];
  }
  
  @synthesize title, artist, series, description, latitude, longitude, location, area, image;
  
  - (CLLocationCoordinate2D)coordinate
  {
      CLLocationCoordinate2D theCoordinate;
      theCoordinate.latitude = [self.latitude doubleValue];
      theCoordinate.longitude = [self.longitude doubleValue];
      return theCoordinate;
  }
  
  
  
  
  @end
  </code></pre>
  
  <p>I then go on to make objects of that class, set their values, and add them to an array in the AppDelegate. Then, in another class, I use:</p>
  
  <pre><code>[self.mapView addAnnotations:mainDelegate.mapAnnotations];
  </code></pre>
  
  <p>to add the annotations to the map. However, when I try to set the "artist" attribute in the viewforannotation method, I get "request for member artist in something not a structure or union." </p>
  
  <p>Obviously, I must be doing this subclassing thing wrong, but what do I change?</p>
  
  <p>Here is the viewforannotation method I have now. The test.artist... line is not working.</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation{
      MKAnnotationView *test=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"reuse"];
      test.image = [UIImage imageNamed:@"pao_pin.png"];
      [test setCanShowCallout:YES];
      [test setUserInteractionEnabled:YES];
      test.rightCalloutAccessoryView =
      [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
      test.artist = annotation.artist;
      return test;    
  }
  </code></pre>
  
  <p>So, should I: <code>annotation = (ArtPiece *)annotation</code>
  In short, my goal is to be able to store a reference to the array position of the object in this annotation was made from so that I can send that to other methods who can access that object for detail views etc. </p>