Xcode swift 失败,退出代码为 254
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24154163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode swift failed with exit code 254
提问by user2280687
I am getting this compiler error in my code and I can't figure out why:
我在我的代码中遇到这个编译器错误,我不知道为什么:
<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
The error is showing up somewhere in the following code segment:
错误显示在以下代码段中的某处:
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
}
(I have more cases that are very similar and am leaving them out for simplicity - the bug isn't in them)
(我有更多非常相似的案例,为了简单起见,我将它们排除在外-错误不在其中)
First Error
第一个错误
One bug is in the line: animalToSwapWith = false
and if I set it to true and comment all the rest out besides the variable initialization lines the error goes away. Also if I comment all of it out but instantiate animalToSwapWith to false the error occurs even though it doesn't when it is instantiated to true.
一个错误在行中:animalToSwapWith = false
如果我将其设置为 true 并注释掉变量初始化行之外的所有其他行,错误就会消失。此外,如果我将所有内容都注释掉但将 AnimalToSwapWith 实例化为 false,即使在实例化为 true 时不会发生错误,也会发生错误。
Second Error
第二个错误
There is a second error in the line:if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
In this line all of these methods have been called earlier in the file with variables of the same types above so knowledge of the methods shouldn't matter.
行中有第二个错误:if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
在这一行中,所有这些方法都已在文件中较早地使用上述相同类型的变量调用,因此对方法的了解无关紧要。
Conclusion
结论
Is there a reason why these two errors are occurring or is it because swift and Xcode-6 are still in beta testing and it is a bug in Xcode? Also note that when commenting the two errors out from each other one at a time the error message is the same.
发生这两个错误是否有原因,还是因为 swift 和 Xcode-6 仍处于 beta 测试阶段,这是 Xcode 中的错误?另请注意,当一次从彼此中注释掉两个错误时,错误消息是相同的。
回答by Pascal
This is a Swift compiler bug, apparently testing for two or more implicitly unwrapped optionals causes the compiler to crash under some/many circumstances. Use Apple's Bugreporterto file this issue, mark it as duplicate of rdar://17212295.
这是一个 Swift 编译器错误,显然测试两个或多个隐式解包选项会导致编译器在某些/许多情况下崩溃。使用Apple 的 Bugreporter提交此问题,将其标记为 rdar://17212295 的副本。
Example
例子
Here's a minimal example that crashes with the same error:
这是一个因相同错误而崩溃的最小示例:
let a: String!
let b: String!
if a && b {
println("have both")
}
Compile on command line as follows and witness the same crash:
按如下方式在命令行上编译并见证相同的崩溃:
$ xcrun swift -v -g crash.swift
回答by AndrewC
I was getting the same error and I tracked it down to this: I was extending NSError
and in the extension was defining an enum
. Moving the enum
definition out of the extension fixed the error.
我遇到了同样的错误,我将其归结为:我正在扩展NSError
并且在扩展中定义了一个enum
. 将enum
定义移出扩展修复了错误。
extension NSError {
enum WYBErrorCodes: Int {
case Fatal = 1000
case XmlParse = 1100
case CoreData = 1200
}
[...]
}
回答by Vitaliy Vashchenko
I'm getting the same error when adopt NSTextViewDelegate protocol for my class. If I remove that protocol, compilation goes fine. Strange indeed.
当我的班级采用 NSTextViewDelegate 协议时,我遇到了同样的错误。如果我删除该协议,编译就可以了。确实奇怪。
回答by Byron Coetsee
For the sake of providing other possible causes and how to fix them; I was trying to set the region of a map view within in dispatch block. If I commented out the setting of the region, the error goes away.
为了提供其他可能的原因以及如何解决它们;我试图在调度块中设置地图视图的区域。如果我注释掉区域的设置,错误就会消失。
dispatch_once(¢erMapLocation, {
// var theSpan: MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
// var theRegion: MKCoordinateRegion = MKCoordinateRegionMake(manager.location.coordinate, theSpan)
// self.map.setRegion(theRegion, animated: true)
})
}
回答by Avi
In my case, i was calling an objective-c function from swift through bridge. Signature was like -
就我而言,我通过桥从 swift 调用了一个 Objective-c 函数。签名就像 -
- (SomeReturnType *)getSomething:(SomeOptions *)options
success:(void (^)(NSArray *response))success
failure:(void (^)(NSError *error))failure;
From swift, i was calling it as follows and getting compile error as "Xcode swift failed with exit code 254" -
从 swift 开始,我按如下方式调用它并收到编译错误“Xcode swift failed with exit code 254” -
ObjCClass().getSomething(nil, success: {(response : Array!) in
}, failure: {(error: NSError!) in
})
changing it to following worked for me -
将其更改为以下对我有用-
ObjCClass().getSomething(nil, success: {(response : [AnyObject]!) in
}, failure: {(error: NSError!) in
})
回答by PMIW
I had this error and the bug was solved in Beta 7 available online today.
我遇到了这个错误,这个错误在今天在线的 Beta 7 中得到了解决。
回答by Jesse Rosalia
I am getting this same error when I try to extend NSArray
to have a foreach
method:
当我尝试扩展NSArray
以拥有一个foreach
方法时,我遇到了同样的错误:
extension NSArray {
func foreach(f: (AnyObject -> ())) {
for elem in self {
f(elem)
}
}
}
It would appear that extending NSArray with func that takes a function argument will cause the same problems. I worked around the issue by defining a forEachInArray
function that takes the NSArray
as an argument:
看起来用带有函数参数的 func 扩展 NSArray 会导致同样的问题。我通过定义一个forEachInArray
以NSArray
为参数的函数来解决这个问题:
func forEachInArray<T>(array: NSArray, f: (AnyObject -> ())) {
for elem in array {
f(elem)
}
}