昨天我安装了官方的Xcode 7,当我尝试打开我的一个Swift项目时,出现了一个警告,说新的Xcode版本想要更新我的Swift代码(或类似的内容)。好的,我接受了,然后出现了"Command failed due to signal: Segmentation fault: 11"的编译错误(如果您想要关于此的详细信息,我可以写下整个错误文本)。有人遇到过相同的问题吗?
谢谢。
编辑
我回退到了Xcode 6.4,一切都没问题,没有编译错误。
昨天我安装了官方的Xcode 7,当我尝试打开我的一个Swift项目时,出现了一个警告,说新的Xcode版本想要更新我的Swift代码(或类似的内容)。好的,我接受了,然后出现了"Command failed due to signal: Segmentation fault: 11"的编译错误(如果您想要关于此的详细信息,我可以写下整个错误文本)。有人遇到过相同的问题吗?
谢谢。
编辑
我回退到了Xcode 6.4,一切都没问题,没有编译错误。
天啊,Xcode有个可怕的bug。看看这篇文章吧。http://blog.bellebethcooper.com/xcode-bug.html 它让我开心了。
变化看起来微不足道,但是实际上是这样的(在我的API客户端类中,我从API获取JSON数据):
我将这段代码改成了:
`let json = try? NSJSONSerialization.JSONObjectWithData(data, options: [])`
变为这样:
`let json = try? NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String: AnyObject]`
这是我曾经遇到的最令人沮丧的调试体验之一,但我希望这篇文章能帮助到其他遇到同样问题的人。如果你通过谷歌搜索遇到了一个困扰你的bug,并且这篇文章并没有帮助到你,我很抱歉。我知道你正在经历什么。不要放弃!
这表示您的代码中缺少一些Required
方法/函数。
在我的情况下,我正在使用ObjectMapper库,在我的类中忘记包括required init()
方法,这导致出现"Command failed due to signal: Segmentation fault: 11"
错误。
required init?(_ map: Map) {
}
请看其他警告信息。
我的情况指向了iOS9和GoogleAds的问题。请参见此处:https://developers.google.com/admob/ios/ios9
简短的答案是禁用构建设置ENABLE_BITCODE。
我的错误:
ld: '/pp/src/shared_js/libs/GoogleMobileAdsSdkiOS-7.3.1/GoogleMobileAds.framework/GoogleMobileAds(GADGestureIdUtil.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
我在将不同的项目转换成Swift3.0时,经常遇到这个问题。
由于这个问题看起来比较动态,每个人都有自己的解决方案而没有通用答案。但是在这个问题中,主要问题是要确定需要处理的位置。
因此,我遵循以下步骤:
确定导致错误的方法
点击错误消息
在我的情况下,AppDelegate 是导致错误的类。
要查找错误行,请浏览长错误描述的结尾。您会发现类似于以下代码:
1. While emitting IR SIL function @_TFC9MyProject11AppDelegate21getNotificationDetailfGSqGVs10DictionaryVs11AnyHashableP___T_ for 'getNotificationDetail' at /Users/ABC/Documents/BitBucket/iOS/2016/Projects/MyProject/AppDelegate/AppDelegate.swift:153:5
在这里,153
是位于 AppDelegate.swift
中的代码行。
func getNotificationDetail(_ launchOptions : [AnyHashable: Any]?) {
if launchOptions != nil {
let dictLaunch = launchOptions! as NSDictionary
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.openRespectiveNotificationScreen), name: NSNotification.Name(rawValue: WebServiceKey.APPMANAGER_SERVICE_CALL_FINISH), object: nil)
inactiveUserInfo = dictLaunch.object(forKey: UIApplicationLaunchOptionsKey.remoteNotification) as? NSDictionary
}
}
首先,在方法内注释掉所有代码并重新构建。然后逐行取消注释,直到找到生成错误的代码行。
找到准确的代码行之后,您可以轻松地修复它。
在我的代码中,我发现该方法的最后一行生成了错误。
因此,我用下面的代码替换它,并成功构建。
inactiveUserInfo = dictLaunch[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary
所以最重要的是谨慎调试。 尝试这种方式,你肯定可以轻松解决错误。
首先,我建议仔细查看构建日志以找到出现问题的文件。在我的情况下,for循环中使用的可选值导致了构建过程中的分段错误。
for i in 0..<hoge?.count {
for i in 0..<hoge!.count {
仔细阅读调试信息。
我遇到了这个错误是因为在if语句中,我不小心使用了单个'='而不是双重'='。
if aString.characters.count = 2 {...}
实现该方法解决了我的问题。这可能是人们面临此问题的原因之一。希望这可以帮助到你。
let stringB: String? = stringA.characters.count = 0 ? nil : stringA
。
let stringB: String? = stringA.characters.count > 0 ? stringA : nil
let stringB: String? = stringA.characters.count == 0 ? nil : stringA
- Manuelfunc test() {
var myDict:[String:String] = [:]
myDict["key"] = "pig"
myDict["key"] += "dog"
var myArray:[String] = []
myArray.append("pig")
myArray[0] += "dog"
}
这会导致分段错误。移除myDict上的+=,一切都正常。
我知道这是一个 bug(字典引用可为空),但编译器不应该像这样崩溃。