Note about MapKitDragAndDrop 3.2

Few weeks ago, I released MapKitDragAndDrop 3.1, a major change to switch away from synthesized by default. Since then, I got some emails about memory leaks, regressions, and suggestions.

By addressing those issues, I’m pleased to announce the MapKitDragAndDrop 3.2.

Two Major Changes

  1. DDAnnotationView now comes with a new class method called +annotationViewWithAnnotation:reuseIdentifier:mapView:, which allows developers to create a draggable annotation view easily. It will return either DDAnnotationView (on iOS3) or drag-enabled MKPinAnnotationView (on iOS4):

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    
        if ([annotation isKindOfClass:[MKUserLocation class]]) {
            return nil;     
        }
    
        static NSString * const kPinAnnotationIdentifier = @"PinIdentifier";
        MKAnnotationView *draggablePinView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:kPinAnnotationIdentifier];
    
        if (draggablePinView) {
            draggablePinView.annotation = annotation;
        } else {
            // Use class method to create DDAnnotationView (on iOS 3) or built-in draggble MKPinAnnotationView (on iOS 4).
            draggablePinView = [DDAnnotationView annotationViewWithAnnotation:annotation reuseIdentifier:kPinAnnotationIdentifier mapView:self.mapView];
    
            if ([draggablePinView isKindOfClass:[DDAnnotationView class]]) {
                // draggablePinView is DDAnnotationView on iOS 3.
            } else {
                // draggablePinView instance will be built-in draggable MKPinAnnotationView when running on iOS 4.
            }
        }       
    
        return draggablePinView;
    }
    
  2. DDAnnotation now init the coordinate correctly.

    Though DDAnnotation is running okay on iOS 4, I would suggest you use MKAnnotation or MKPlacemark on iOS 4 instead. The reason for this is because DDAnnotation is designed for iOS 3 when MKAnnotation only has readonly coordinate property (I re-decleare it to readwrite in header file), but starting from iOS 4, Apple had provided a method to change coordinate:

    @protocol MKAnnotation <NSObject>
    
    // Center latitude and longitude of the annotion view.
    @property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
    
    @optional
    
    // Title and subtitle for use by selection UI.
    - (NSString *)title;
    - (NSString *)subtitle;
    
    // Called as a result of dragging an annotation view.
    - (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
    
    @end
    

    So you can change coordinate through that on iOS 4, and no longer need to re-declare the property.

License

Source code is licensed under MIT license.
You can download it from github.

References

  1. digdog posted this