Using the undefined identifier "enumerate" after Swift Migration

I have an array called customAnnotationsArray into which I add the (Annotations) to class. This class, annotations, is a subclass of MKAnnotation and NSObject. In my previous version of Swift, the code for (index, value) in enumerate(customAnnotationArray)worked wonderfully to extract an index. Now I say that there is β€œUse an unresolved identifier toβ€œ list. ”I examined a ton and can not find any resources. How can I fix this?

//Annotations array (gets populated with annotations on data load)
var customAnnotationArray = [Annotations]()


//When tapping the MKAnnotationView.
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
             calloutAccessoryControlTapped control: UIControl) {

    let theAnnotation = view.annotation

    //ERROR BELOW IN enumerate "Use of unresolved identifier 'enumerate'
    for (index, value) in enumerate(customAnnotationArray) {

        if value === theAnnotation {
            //print("The annotation array index is \(index)")

            //Im passing these variables in prepareForSegue to VC
            markerIndex = index
            addressSelected = addressArray[index]
        }
    }

    let vc = storyboard.instantiateViewController(withIdentifier: "updateRecordVC")
    self.navigationController!.pushViewController(vc, animated: true)  
}



//Annotations class if that helps.
class Annotations: NSObject, MKAnnotation {
    let title: String?
    let locationName: String
    let coordinate: CLLocationCoordinate2D
    let pinColor: MKPinAnnotationColor

    init(title: String, coordinate: CLLocationCoordinate2D, locationName: String, pinColor:MKPinAnnotationColor) {
        self.title = title
        self.coordinate = coordinate
        self.locationName = locationName
        self.pinColor = pinColor      
        super.init()
    }

    var subtitle: String? {
        return locationName
    }

    func currentPinColor(_ currentUser: Double) -> MKPinAnnotationColor?   {
        switch currentUser {
        case 0:
            return .green
        case 1:
            return .purple
        default:
            return .green
        }
    }
}
+4
source share
1 answer

Try using instead enumerated():

for (index, value) in customAnnotationArray.enumerated()

Hope this is what you are looking for ...

+13
source

Source: https://habr.com/ru/post/1658588/


All Articles