Xcode/Swift 错误:由于信号导致命令失败:分段错误:11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27604758/
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 error: Command failed due to signal: Segmentation fault: 11
提问by Peyman
I am trying to call a function of a singleton class with completion handler argument but I get "Command failed due to signal: Segmentation fault: 11" error. I am using Xcode 6.2 (6C101) and trying to build for iOS 8 on iPhone 6 simulator. Here is the singlton class:
我正在尝试使用完成处理程序参数调用单例类的函数,但出现“由于信号导致命令失败:分段错误:11”错误。我正在使用 Xcode 6.2 (6C101) 并尝试在 iPhone 6 模拟器上为 iOS 8 构建。这是单顿类:
public class ClientManager {
public class var sharedInstance: ClientManager {
struct Singleton {
static let instance = ClientManager()
}
return Singleton.instance
}
private init() {
}
public func fetchServiceInfo(serviceName: String, completionHandler: (JSON?, NSError?) -> Void) {
Alamofire.request(.GET, Router.ServiceInfo(serviceName)).responseJSON { (req, res, json, error) in
completionHandler(JSON(json!), error)
}
}
}
And when I call fetchServiceInfo
function within a view controller, Xcode crashes (SourceKitService Crashed):
当我fetchServiceInfo
在视图控制器中调用函数时,Xcode 崩溃(SourceKitService Crashed):
ClientManager.sharedInstance.fetchServiceInfo("default") { (json, error) in
println(json)
}
However, if I call the same function within the init
method of ClientManager
it works properly:
但是,如果我在它的init
方法中调用相同的函数,ClientManager
它可以正常工作:
private init() {
self.fetchServiceInfo("default") { (json, error) in
println(json)
}
}
I am using Alamofire
and SwiftyJSON
libraries.
我正在使用Alamofire
和SwiftyJSON
库。
回答by Carlos García
?Is posible you are using SwiftyJSON as framework, cocoapods or git submodule? Look at https://github.com/SwiftyJSON/SwiftyJSON/issues/125Using SwiftyJSON.swift file into your project must work fine
?您是否可以使用 SwiftyJSON 作为框架、cocoapods 或 git 子模块?查看https://github.com/SwiftyJSON/SwiftyJSON/issues/125Using SwiftyJSON.swift file into your project must work fine
回答by Orlin Georgiev
As Carlos Garcia correctly pointed out, the problem is with compiling SwiftyJSON. In his provided link https://github.com/SwiftyJSON/SwiftyJSON/issues/125, check the solution by nunogoncalves. In a nutshell, you MUST use the closure JSON parameter at least once in the closure body. Here is what I did:
正如 Carlos Garcia 正确指出的那样,问题在于编译 SwiftyJSON。在他提供的链接https://github.com/SwiftyJSON/SwiftyJSON/issues/125 中,检查 nunogoncalves 的解决方案。简而言之,您必须在闭包主体中至少使用一次闭包 JSON 参数。这是我所做的:
NetworkManager.sharedInstance.loadOrderDetails(187, onComplete: { (json, errorMessage) -> () in
json?["aaa"] //this useless line fixes the compiler crash
//the rest of your code here...
});