【问题标题】:Xcode/Swift error: Command failed due to signal: Segmentation fault: 11Xcode/Swift 错误:由于信号而导致命令失败:分段错误:11
【发布时间】:2015-02-20 16:11:14
【问题描述】:

我正在尝试使用完成处理程序参数调用单例类的函数,但我收到“由于信号导致命令失败:分段错误: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)
        }
    }

}

当我在视图控制器中调用 fetchServiceInfo 函数时,Xcode 崩溃(SourceKitService Crashed):

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

但是,如果我在 ClientManagerinit 方法中调用相同的函数,它可以正常工作:

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

我正在使用 AlamofireSwiftyJSON 库。

【问题讨论】:

  • 您是否偶然使用了 SwiftyJSON 框架?这意味着不仅仅是获取文件的副本。在使用框架时,我一直无法使用 JSON 对象作为参数。如果我复制文件并将其添加到我的项目中,尽管它似乎工作正常。
  • 是的!我之前将它作为框架,但现在我将它作为我的项目中的一个 swift 文件,它工作正常。

标签: ios xcode swift singleton


【解决方案1】:

¿您是否可以使用 SwiftyJSON 作为框架、cocoapods 或 git 子模块?看https://github.com/SwiftyJSON/SwiftyJSON/issues/125 在您的项目中使用 SwiftyJSON.swift 文件必须可以正常工作

【讨论】:

  • 不推荐使用仅链接的答案。
【解决方案2】:

正如 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...
});

【讨论】:

    猜你喜欢
    • 2015-12-18
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多