Adding a (convenient) computed height
property to UIView
in my UIViewExtension.swift
file is causing the Swift compiler to segfault...
When you run into a compiler segfault in Swift, you don't get a handy line number and error message. Here's how you can track the problem down:
SegFaultDebugger.swift
in your project.SegFaultDebugger.swift
.At this point, one of three things happens:
SegFaultDebugger.swift
back to the original file and move a different set of methods into SegFaultDebugger.swift
. RepeatSegFaultDebugger.swift
: Great! Now use binary search to pin the segfault down to a specific method until you can figure out what construct is causing it.In Xcode 7, you can click on the error in the Debug Navigator and you'll be shown an expanded view of the crashes. Clicking on the hamburger button on the right expands the error, and if you scroll all the way down to the bottom of the expanded error message, you will see where it comes from.
For me, I had two of those segmentation fault errors. In the picture above, the first one is what it looks like when collapsed, the second is when you expand the hamburger button. At the very bottom of the expanded gray box, you'll see a message that says where the compiler crashed.
Note however that the error message may at times be not informative enough, so while it tells you where it crashed, it doesn't always say why and how to fix it. Getting rid of this error is still very much a matter of guesswork.
Like @Fjohn said, this was an issue related to unwrapping an optional for me (broke in both Xcode 7.0 beta 6 and Xcode 7). In my case, I was not unwrapping optional of the optional (what tipped me off was double ?? in the descriptor. Using if let solved the issue
For me the following caused a segfault while type
is an optional:
switch type {
case .aType:
// Do Something
default:
break
}
and this solved it:
switch type {
case .Some(.aType):
// Do Something
default:
break
}
I got this error while extending one of my protocols and mistyped and optional type argument.
protocol SomeProtocolName: class {
var someProtocolVariable: String { get set }
func someProtocolFunction(someProtocolVariable: String)
}
// MARK:
extension SomeProtocolName {
func someProtocolFunction(someProtocolVariable: String?) {
self.someProtocolVariable = someProtocolVariable
}
}
The difference in function arguments String
in prototype and String?
in extension caused Segmentation Fault 11.
You can also have this problem if you declare a condition with an unwrapped Bool as a property