我在我的代码中遇到这个编译器错误,我不知道为什么:
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
错误出现在以下代码段的某处:
var animalViewToSwap: AnimalView = animalViewMatrix.objectAtRow(0, andColumn: 0) as AnimalView
var currentRow = 0
var currentColumn = 0
var animalToSwapWith = true
var currentLocation = animalViewMatrix.findLocationOfObject(animalView)
currentRow = Int(currentLocation.row) - 1
currentColumn = Int(currentLocation.column) - 1
var rowDisplacement = 0
var columnDisplacement = 0
switch inDirection{
case "left":
columnDisplacement = withDistance * -1
if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
{
animalToSwapWith = true;
}
else { animalToSwapWith = false }
default:
println("error")
animalToSwapWith = false
break
}
(我有更多非常相似的案例,为简单起见,我将它们排除在外 - 错误不在其中)
第一个错误
行中有一个错误:animalToSwapWith = false
,如果我将其设置为 true 并注释除变量初始化行之外的所有其余部分,错误就会消失。此外,如果我将所有内容都注释掉但将 animalToSwapWith 实例化为 false,则会发生错误,即使它在实例化为 true 时不会发生。
第二个错误
行中还有第二个错误:if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
在这一行中,所有这些方法都已在文件的前面使用上述相同类型的变量调用,因此了解这些方法无关紧要。
结论
这两个错误的发生是有原因的,还是因为 swift 和 Xcode-6 仍在 beta 测试中,这是 Xcode 中的错误?另请注意,一次将两个错误相互注释掉时,错误消息是相同的。
最佳答案
这是一个 Swift 编译器错误,显然测试两个或多个隐式展开的可选值会导致编译器在某些/许多情况下崩溃。使用 Apple's Bugreporter要提交此问题,请将其标记为 rdar://17212295 的副本。
例子
这是一个因相同错误而崩溃的最小示例:
let a: String!
let b: String!
if a && b {
println("have both")
}
按如下方式在命令行上编译并见证相同的崩溃:
$ xcrun swift -v -g crash.swift
关于ios - Xcode swift 失败,退出代码为 254,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24154163/