Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of unresolved identifier 'enumerate' after Swift Migration

Tags:

ios

I have an array, called customAnnotationsArray, in which I am appending a class (Annotations) to. This class, Annotations, is a subclass of MKAnnotation and NSObject. In my previous Swift version, the code for (index, value) in enumerate(customAnnotationArray) worked wonderfully to extract the pin's index. Now, it is saying that there is "Use of unresolved identifier 'enumerate'. Ive researched a ton and cannot find any resources. How do 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's 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
        }
    }
}
like image 731
Josh O'Connor Avatar asked Oct 23 '16 06:10

Josh O'Connor


1 Answers

Try using the enumerated() method instead:

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

Hopefully this is what you're looking for...

like image 84
l'L'l Avatar answered Nov 20 '22 04:11

l'L'l