在Swift Migration之后使用未解析的标识符'enumerate'

时间:2016-10-23 06:42:11

标签: ios

我有一个名为customAnnotationsArray的数组,我在其中附加一个类(注释)。这个类Annotations是MKAnnotation和NSObject的子类。在我以前的Swift版本中,代码for (index, value) in enumerate(customAnnotationArray)非常有效地提取了引脚的索引。现在,它说有“使用未解析的标识符'枚举'。我已经研究了很多,找不到任何资源。我该如何解决这个问题?

//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
        }
    }
}

1 个答案:

答案 0 :(得分:18)

请尝试使用enumerated()方法:

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

希望这就是你要找的......