2015-10-26 62 views
1

我正在開發一個應用程序的ios 9.自從我更新到7.1版本我有這個錯誤: 命令由於信號失敗:分段錯誤: 11命令由於信號失敗:分段錯誤:更新到Xcode 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 
} 

錯誤是由註釋行引起。請幫忙

回答

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

+0

您好,有效ADBaseAnnotation是共享類。編譯器由於未知錯誤而下降,不是語法錯誤。在更新Xcode之前,正在使用此代碼。 我測試了你的代碼,工作正常。 Gracias! – ClarkXP

+0

您的代碼可能是正確的,但對編譯器來說太混亂了。斯威夫特剛剛一歲!我對元組上的映射過濾器有一個類似的問題,它是無法解決的一些奇怪的方法鏈。 –

相關問題