【问题标题】:Swift 3 - 'EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0)' Error斯威夫特 3 - 'EXC_BAD_INSTRUCTION(代码 = EXC_1386_INVOP,子代码 = 0x0)' 错误
【发布时间】:2017-04-28 18:47:53
【问题描述】:

我正在 swift 3 中开发一个迷宫游戏,它可以编译,但是当我运行它时出现 EXC_BAD_INSTRUCTION 错误。我对 swift 比较陌生,所以我不知道如何正确调试它。以下是出现错误的代码:

init(window:SKScene, width:Int, height:Int){
    widthOfBoard = width
    heightOfBoard = height


    for i in 0..<widthOfBoard {
        var temp:[cell]!
        for j in 0..<heightOfBoard {
            let tempCell = cell(x: i, y: j, boardWidth: widthOfBoard, boardHeight: heightOfBoard, screenSize: window.frame)
            temp.append(tempCell)
        }
        cells.append(temp)
    }
    stackOfCells.append(cells[0][0])
    recursiveMaze(currentX: 0, currentY: 0, window: window)
}

我收到了cells.append(temp) 的错误。

我也收到了每个错误 these locations.

【问题讨论】:

    标签: ios swift exc-bad-instruction


    【解决方案1】:

    temp 是导致崩溃的nil。任何不小心写的感叹号都可能导致崩溃。

    声明了变量temp,但如果您想向其追加项目,则必须初始化数组:

    var temp = [cell]()
    

    顺便说一句:类名应该以大写字母开头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      相关资源
      最近更新 更多