Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 3-&x27;EXC_BAD_指令(代码=EXC_1386_INVOP,子代码=0x0)和x27;错误_Ios_Swift_Exc Bad Instruction - Fatal编程技术网

Ios Swift 3-&x27;EXC_BAD_指令(代码=EXC_1386_INVOP,子代码=0x0)和x27;错误

Ios Swift 3-&x27;EXC_BAD_指令(代码=EXC_1386_INVOP,子代码=0x0)和x27;错误,ios,swift,exc-bad-instruction,Ios,Swift,Exc Bad Instruction,我正在用swift 3编写一个迷宫游戏,它可以编译,但是当我运行它时,我得到了EXC_BAD_指令错误。我对swift比较陌生,所以我不知道如何正确地调试它。下面是获取错误的一段代码: init(window:SKScene, width:Int, height:Int){ widthOfBoard = width heightOfBoard = height for i in 0..<widthOfBoard { var temp:[cell]

我正在用swift 3编写一个迷宫游戏,它可以编译,但是当我运行它时,我得到了EXC_BAD_指令错误。我对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)
}
init(窗口:SKScene,宽度:Int,高度:Int){
板的宽度=宽度
板的高度=高度

对于0中的i..
temp
是导致崩溃的
nil
。任何不小心写的感叹号都可能导致崩溃

声明了变量
temp
,但如果要向数组中添加项,则必须初始化该数组:

var temp = [cell]()

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

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

声明了变量
temp
,但如果要向数组中添加项,则必须初始化该数组:

var temp = [cell]()
顺便说一下:类名应该以大写字母开头