【问题标题】:error (but only on iPhone 4s and iPad 2) EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)错误(但仅在 iPhone 4s 和 iPad 2 上) EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)
【发布时间】:2016-08-18 19:20:00
【问题描述】:

我正在制作的应用程序中出现此错误,但仅限于 iPhone 4s 和 iPad 2 EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)

当我递增一个整数时,错误会导致一个断点

colorNum++

这对我来说没有意义

我认为这可能是因为我从这段代码中调用了一个 web:complete 函数: 有谁知道如何解决这个问题

    var session = NSURLSession.sharedSession()

    var task = session.dataTaskWithURL(urlPath!) {
        data, response, error -> Void in
        if ((error) != nil) {
            println(error!.localizedDescription)
        }
        var jsonError : NSError?
        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as? Dictionary<String, AnyObject>
        if (jsonError != nil) {
            println(jsonError!.localizedDescription)
        }

        if let apiDel = self.delegate? {
            if ((jsonResult) != nil) {
                dispatch_async(dispatch_get_main_queue(), {
                    apiDel.didFinishGettingHorror(jsonResult!)
                    self.pageNum++
                })
            }
        }
    }
    task.resume()
}

【问题讨论】:

  • 我们需要看看实际异常发生在哪里。而且我认为您的意思是“导致异常”而不是“导致断点”。
  • 在apiDelegate的回调函数中调用某个方法时发生。
  • 是的,这是个例外 :) 抱歉
  • 整数增量在那个函数中。这个异常可能是因为我在执行时通过 apiDel 回调意外调用了该方法

标签: json xcode swift


【解决方案1】:

我假设您的pageNum 变量(隐式)声明为Int 类型。 iPhone 4S、iPhone 5、iPad 2、iPad Retina 是 32 位设备,其中Int 是一个 32 位整数。当您增加pageNum 时,您实际上可能会使其溢出,从而导致EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)

iOS Swift - EXC_BAD_INSTRUCTION on certain devices

我有同样的问题。阅读了这个帖子和我上面链接的那个帖子让我意识到问题出在哪里。

【讨论】:

    猜你喜欢
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多