2016-10-23 5 views
4

私はクラス(注釈)を追加する予定のcustomAnnotationsArrayという配列を持っています。このクラスAnnotationsはMKAnnotationとNSObjectのサブクラスです。以前のSwiftバージョンでは、コードfor (index, value) in enumerate(customAnnotationArray)がすばらしく働いてピンのインデックスを抽出しました。さて、「『列挙』未解決の識別子の使用があることを言っているアイブ氏は、トンを調査し、すべてのリソースを見つけることができない私は、この問題を解決するにはどうすればよいSwift移行後の未解決の識別子 '列挙'の使用

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

答えて

12

代わりenumerated()方法を使用してみてください:。。?

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

うまくいけば、これはあなたが探しているものです...

+0

はありがとうございました!ImはXcodeのがあなたのために、この –

+0

おかげで仲間... +1のためのクイックフィックスのオプションを持っていませんでし驚か –

関連する問題