【问题标题】:Command failed due to signal: Segmentation fault: 11 after update to Xcode 7.1由于信号,命令失败:分段错误:更新到 Xcode 7.1 后为 11
【发布时间】:2015-10-26 00:43:31
【问题描述】:

我正在为 ios 9 开发应用程序。自从我更新到 7.1 版本后,我遇到了这个错误: 由于信号导致命令失败:分段错误:11

查看代码,我发现是这段代码导致了这个错误:

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
}

错误是由注释行引起的。请帮忙

【问题讨论】:

    标签: ios swift2 xcode7.1


    【解决方案1】:

    这是编译器确实失败的问题,还是在正常编译后仍会突出显示发生错误的代码行?当编译器对我编写的代码感到困惑并且无法编译并且在内部发生某种崩溃时,我经常会遇到这种情况。如果是这种情况,您可以在编译日志中找到更详细的信息。通常这是我自己的错,但编译器仍然太新,无法提供良好的反馈或以优雅的方式处理这种情况。

    我不知道确切的问题,但我注意到有关您的代码的一些事情。对我来说很有趣的是:

    if let normal = annotation as? NormalParking {
            anView = normal.getAnnotationView(annotation, reuseIdentifier: normal.getReuseId())
        }
    

    为什么不使用相同的转换变量,例如:

    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()

    【讨论】:

    • 嗨,实际上 ADBaseAnnotation 是一个共享类。编译器因未知错误而下降,不是语法错误。在更新 Xcode 之前,正在使用此代码。我测试了你的代码并且工作正常。谢谢!
    • 您的代码可能是正确的,但对编译器来说太混乱了。斯威夫特还不到一岁!我对元组上的地图过滤器有类似的问题,一些奇怪的方法链无法解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2017-02-06
    相关资源
    最近更新 更多