我升级到更新的 Swift 编译器并遇到了这个编译器错误,我不知道如何解决。我有一堆从 MKMapViewDelegate 声明的 mapView 函数。除了引发此错误的这个之外,它们似乎都匹配:
ViewController.swift:137:10:Objective-C 方法 'mapView:viewForAnnotation:' 提供的方法 'mapView( :viewForAnnotation:)' 与协议 'MKMapViewDelegate' 中的可选要求方法 'mapView( :viewForAnnotation:)' 冲突</p >
ViewController.swift:12:7:“ViewController”类在此处声明符合协议“MKMapViewDelegate”
/ViewController.swift:137:10: 此处声明的需求'mapView(_:viewForAnnotation:)' (MapKit.MKMapViewDelegate)
我查看了 MKMapViewDelegate 方法,我认为我正确匹配了它,所以我对需要更正的更改感到困惑。从那里我看到
可选 func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
这是我下面的声明,它会引发错误。
class ViewController: UIViewController, MKMapViewDelegate {
func mapView(aMapView: MKMapView!, viewForAnnotation annotation: CustomMapPinAnnotation!) -> MKAnnotationView! {
//The error is thrown here on the m in mapView
}
}