Ios 命令失败,原因是信号:分段故障:11更新到Xcode 7.1后
我正在为ios 9开发一个应用程序。自从我更新到7.1版本后,我出现了以下错误: 由于信号:分段故障:11,命令失败 查看代码时,我发现此代码导致此错误:Ios 命令失败,原因是信号:分段故障:11更新到Xcode 7.1后,ios,swift2,xcode7.1,Ios,Swift2,Xcode7.1,我正在为ios 9开发一个应用程序。自从我更新到7.1版本后,我出现了以下错误: 由于信号:分段故障:11,命令失败 查看代码时,我发现此代码导致此错误: func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if !(annotation is ADBaseAnnotation){ print("No es ADBase
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is ADBaseAnnotation){
print("No es ADBaseAnnotation",terminator:"\n")
return nil
}
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier((annotation as! ADBaseAnnotation).getReuseId())
if let normal = annotation as? NormalParking {
//anView = normal.getAnnotationView(annotation, reuseIdentifier: normal.getReuseId())
} else if let hightlight = annotation as? HightLightParking{
//anView = hightlight.getAnnotationView(annotation, reuseIdentifier: hightlight.getReuseId())
}
return anView
}
错误是由注释行引起的。请帮助这是一个编译器确实失败的问题,还是在编译后仍会像正常情况一样突出显示出错的代码行?当编译器对我编写的代码感到困惑,无法编译并且内部崩溃时,我经常会遇到这种情况。如果是这样,您可以在编译日志中找到更详细的信息。通常这是我自己的错,但编译器还是太新,无法提供良好的反馈或以优雅的方式处理这种情况 我没有意识到确切的问题,但我注意到您的代码中有一些地方。我觉得有趣的是:
if let normal = annotation as? NormalParking {
anView = normal.getAnnotationView(annotation, reuseIdentifier: normal.getReuseId())
}
为什么不使用相同的casted变量,如:
if let normal = annotation as? NormalParking {
anView = normal.getAnnotationView(normal, reuseIdentifier: normal.getReuseId())
}
而且你在施法后也会做同样的事情,实际上你根本不需要施法
例如:
guard let annotation = annotation as? ADBaseAnnotation else {
print("No es ADBaseAnnotation",terminator:"\n")
return nil
}
if annotation is NormalParking || annotation is HightLightParking {
return annotation.getAnnotationView(annotation, reuseIdentifier: annotation.getReuseId())
}
return mapView.dequeueReusableAnnotationViewWithIdentifier(annotation).getReuseId())
我假设ADBaseAnnotation是一个定义getReuseId()的共享基类,而您的停车场实现覆盖了getReuseId()Hi,实际上ADBaseAnnotation是一个共享类。编译器出现未知错误,不是语法错误。在更新Xcode之前,您正在使用此代码。我测试了你的代码,效果很好。格雷西亚斯!您的代码可能是正确的,但对编译器来说太混乱了。斯威夫特才一岁!我对元组上的映射过滤器也有类似的问题,它无法解决一些奇怪的方法链。