To customize, let's use the demo we built in the previous section. We will see how to customize the annotation object and the annotation view:
- Add a new Swift source file for a new class, called CustomAnnotation.
- Change the CustomAnnotation class to conform to the MKAnnotation protocol. The protocol requires you to define the coordinate property so that the map view can understand the location of the annotation:
import UIKit import MapKit class CustomAnnotation: NSObject, MKAnnotation{ var coordinate: CLLocationCoordinate2D var title: String? = "" var color: UIColor override init() { coordinate = CLLocationCoordinate2D() color = UIColor.black } init(location: CLLocationCoordinate2D) { self.coordinate = location color = ...