gpt4 book ai didi

ios - 在 Swift 迁移后使用未解析的标识符 'enumerate'

转载 作者:可可西里 更新时间:2023-11-01 04:08:39 24 4
gpt4 key购买 nike

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

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

最佳答案

尝试使用 enumerated() 方法:

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

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

关于ios - 在 Swift 迁移后使用未解析的标识符 'enumerate',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com