Xcode / Swift error: command failed due to signal: Segmentation error: 11

I try to call a singleton class function with an argument to the completion handler, but I get "Command failed because of error: Segmentation failed: 11". I am using Xcode 6.2 (6C101) and trying to build for iOS 8 on the iPhone 6 simulator. Here is the singlton 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) } } } 

And when I call the fetchServiceInfo function in the view controller, the Xcode (SourceKitService Crashed) crashes:

 ClientManager.sharedInstance.fetchServiceInfo("default") { (json, error) in println(json) } 

However, if I call the same function in the init method of the ClientManager , it works correctly:

 private init() { self.fetchServiceInfo("default") { (json, error) in println(json) } } 

I use the Alamofire and SwiftyJSON .

+1
source share
2 answers

¿Is it possible that you are using SwiftyJSON as a framework, cocoapods or git submodule? See https://github.com/SwiftyJSON/SwiftyJSON/issues/125 Using the SwiftyJSON.swift file in your project should work fine

+1
source

As Carlos Garcia correctly pointed out, the problem is compiling SwiftyJSON. In his provided link https://github.com/SwiftyJSON/SwiftyJSON/issues/125 , check out the nunogoncalves solution. In a nutshell, you MUST use the JSON close option at least once in the closure body. Here is what I did:

 NetworkManager.sharedInstance.loadOrderDetails(187, onComplete: { (json, errorMessage) -> () in json?["aaa"] //this useless line fixes the compiler crash //the rest of your code here... }); 
0
source

All Articles