Search code examples
iosswift2xcode7.1

Command failed due to signal: Segmentation fault: 11 after update to Xcode 7.1


I'm developing an app for ios 9. since that I updated to 7.1 version I have this error: Command failed due to signal: Segmentation fault: 11

Looking in the code, I found that this code are causing this error:

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
}

The error is causing by the commented lines. Please help


Solution

  • Is this a problem where the compiler really fails or it will still highlight the lines of code where the error occurred after compiling like normal? I have this often when the compiler is confused about the code I've written and can't compile and sort of crashes internally. You can find more detailed information in the compilation log if that's the case. Usually it's my own fault but the compiler is still too new to give good feedback or handle the situation in an elegant way.

    I don't recognise the exact problem but I notice some things about your code. What looks funny to me is the following:

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

    Why don't you use the same casted variable like:

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

    Also you do exactly the same after casting, you don't need to cast at all actually.

    For example:

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

    I am assuming ADBaseAnnotation is a shared base class defining getReuseId() and your Parking implementations override getReuseId()