斯威夫特 - 发布版本崩溃,除非我关掉优化非我、斯威夫特、版本

2023-09-08 00:30:24 作者:情感贩卖机

这是X上code 6.2。

如果我运行在发布模式的应用程序会崩溃,但与优化掉它不会崩溃。在code看起来简单。我已经设定ObjC了十多年,所以没有新的节目,等等。

我注意到,在32位运行良好的释放模式(最快-O),但在64位真正的iOS硬件崩溃。

特朗普要凉了 知名女星diss特朗普 我们会在11月票选把你踢出局

这是一个编译器错误?或者是有可能有差迅速只能对一些编译器设置崩溃(这可以在C发生!)。

我有code,但我不知道这会有所帮助。

 类FUNC attemptLogin(completionHandler:(结果:JSON?错误:NSError) - >()?){
    //看来,这些变量不工作,在完成块64与优化。
    让电子邮件= User.email
    让密码= user.password的

    //设置登录。
    让参数:[字符串:AnyObject] = [
        行动:登录,
        登录: [
            电子邮件:电子邮件,
            密码:密码,
            类型:User.type
        ]
    ]

    //关火REST POST异步
    请求(.POST,的baseUrl,参数:参数编码:.JSON)
        .responseSwiftyJSON {(请求,响应jsonDict,误差)在

                //在64位版本模式,事情是严重不利位置。
            的println(jsonDict尝试登录:)
            打印(jsonDict)

            如果让令牌= jsonDict [登录] [令牌。字符串{
                的println(标记发现是:+令牌)
                User.token =令牌;
                User.email =电子邮件;
                user.password的=密码;
                completionHandler(结果:jsonDict,错误:无)
            } 其他 {
                的println(无令牌)
                User.token =;
                User.email =;
                user.password的=;

                让errorNS = NSError(域名:stethIoUser,code:404,用户信息:无)

                completionHandler(结果:jsonDict,错误:errorNS)
            }
        }
}
 

解决方案

昨天我也有类似的情况。

我在运行X code 6.2。

如果我跑在Release模式我的应用程序会崩溃,但与优化掉它并没有崩溃,在释放模式。 (在调试模式下,它运行得很好。)

这个问题?该行code:

 让部分=拆分(columnLetters,{$ 0 ==,})
 

是的。就是这样。该分割函数只是没拆我的字符串。相反,它分配整个原始字符串传递给零件组列的第一个元素。毫不奇怪,这导致崩溃以后在应用程序。

我取代了线code这一点,和它的工作:

 让部分= columnLetters.componentsSeparatedByString()
 

这个错误是特别难以追查,原因如下:

该应用程序在测试过程中运行正常,因为它是在调试模式下进行编译。它花了一些时间来消除其他因素(iOS版,督促对测试数据)来实现的崩溃只发生在释放模式。

该应用程序的发布模式工作,如果我们关闭的优化。

这次事故是不相关的,因为我们部署了两个月前我们最后一次成功的发行版中引入任何新的code。我们使用分割功能没有问题,已经到现在。

崩溃并没有出现在code线,这是问题。它在应用程序后发生,为的字符串没有得到拆分的结果。

在code编译罚款释放模式。有没有编译错误指向一个问题与分割功能。该功能根本就没有分割字符串。

我没有X上code 6.3或更高版本测试了这个。 (对于其他原因,我们无法升级至X code 6.3 /雨燕1.2 pvented $ P $,但会升级很快)。

This is on XCode 6.2.

If I run the app in release mode it will crash, but with optimizations off it does not crash. The code looks straightforward. I have programmed ObjC for over a decade, so not new to programming, etc.

I note that in 32 bit it runs fine in release mode (Fastest -O), but on 64 bit real iOS hardware it crashes.

Is this a compiler bug ? Or is it possible to have poor swift that crashes only for some compiler settings (which can happen in C!).

I include code, but I'm not sure that it will help.

class func attemptLogin(completionHandler: (result: JSON?, error: NSError?) -> ()) {
    // It appears that these variables are not working in the completion block in 64 with optimization on.
    let email = User.email
    let password = User.password

    // setup login.
    let parameters: [String : AnyObject] = [
        "action": "login",
        "login": [
            "email": email,
            "password": password,
            "type": User.type
        ]
    ]

    // Fire off REST POST Async
    request(.POST, baseUrl, parameters: parameters, encoding: .JSON)
        .responseSwiftyJSON { (request, response, jsonDict, error) in

                // in release mode on 64 bit, things are seriously bad here. 
            println("jsonDict login attempt: ")
            print(jsonDict)

            if let token = jsonDict["login"]["token"].string {
                println("token found is: " + token)
                User.token = token;
                User.email = email;
                User.password = password;
                completionHandler(result: jsonDict, error: nil)
            } else {
                println("No Token")
                User.token = "";
                User.email = "";
                User.password = "";

                let errorNS = NSError(domain: "stethIoUser", code: 404, userInfo: nil)

                completionHandler(result: jsonDict, error: errorNS)
            }
        }
}

解决方案

I had a similar situation yesterday.

I was running Xcode 6.2.

If I ran my app in Release mode it would crash, but with optimizations off it did not crash in Release mode. (In Debug mode it ran fine.)

The problem? This line of code:

let parts = split(columnLetters, { $0 == "," })

Yep. That was it. The split function simply did not split my string. Instead, it assigned the entire original string to the first element of the parts array. Not surprisingly, this led to a crash later in the app.

I replaced that line of code with this, and it worked:

let parts = columnLetters.componentsSeparatedByString(",")

This bug was particularly difficult to track down for the following reasons:

The app ran fine during testing, since it was compiled in Debug mode. It took some time to eliminate other factors (iOS version, prod vs. test data) to realize that the crash only occurred in Release mode.

The app worked in Release mode if we turned off optimizations.

The crash was not related to any new code introduced since our last successful Release version that we deployed two months ago. We had been using the split function without issue until now.

The crash did not occur on the line of code that was the problem. It occurred later in the app, as a consequence of the string not getting split.

The code compiled fine in Release mode. There was no compile error that pointed to an issue with the split function. The function simply did not split the string.

I have not tested this on Xcode 6.3 or later. (For other reasons, we were prevented from upgrading to Xcode 6.3 / Swift 1.2, but will upgrade soon.)

 
精彩推荐
图片推荐