-2

I am trying to change the color of the pin used in my map in MapKit in Xcode. I found this in the Apple Developer Documentation:

Declaration (iOS, tvOS):

var pinTintColor: UIColor! { get set }

I am new to code and I can't figure out what I should put in get and set, could you please help me?

Thank you!

Kon
  • 4,023
  • 4
  • 24
  • 38
Eric
  • 1
  • 1
  • 1

1 Answers1

0

Try the following code:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView?.pinTintColor = .purple

    }
    else {
        pinView?.annotation = annotation
    }

    return pinView
}
Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52