Xcode / Swift错误:命令由于信号失败:分段错误:11
我想用完成处理程序参数调用一个单例类的函数,但我得到“命令失败,由于信号:分段错误:11”错误。 我正在使用Xcode 6.2(6C101),并尝试在iPhone 6模拟器上为iOS 8构build。 这是一个单人class:
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) } } }
当我在视图控制器中调用fetchServiceInfo
函数时,Xcode崩溃(SourceKitService Crashed):
ClientManager.sharedInstance.fetchServiceInfo("default") { (json, error) in println(json) }
但是,如果我在ClientManager
的init
方法中调用相同的函数,它将正常工作:
private init() { self.fetchServiceInfo("default") { (json, error) in println(json) } }
我正在使用Alamofire
和SwiftyJSON
库。
¿是否正在使用SwiftyJSON作为框架,cocoapods或git子模块? 看看https://github.com/SwiftyJSON/SwiftyJSON/issues/125在你的项目中使用SwiftyJSON.swift文件必须正常工作
正如卡洛斯·加西亚正确指出的,问题在于编译SwiftyJSON。 在他提供的链接https://github.com/SwiftyJSON/SwiftyJSON/issues/125 ,检查由nunogoncalves解决scheme。 简而言之,您必须至less在闭包体中使用闭包JSON参数。 这是我做的:
NetworkManager.sharedInstance.loadOrderDetails(187, onComplete: { (json, errorMessage) -> () in json?["aaa"] //this useless line fixes the compiler crash //the rest of your code here... });