致命错误:指数超出范围(迅捷)

时间:2016-06-21 05:32:38

标签: ios xcode swift indexing

以下是hackerrank编辑器中的代码。我在语言swift中得到了一个超出范围的fatoal错误索引。我在我的操场上有类似的代码,但不是取一个readLine我只是得到一个随机数来填充我的2D数组。这是在我的操场上工作

// hackerrank https://ghostbin.com/paste/jtc5k

// xcode的工作原理 https://ghostbin.com/paste/xqqh4

1 个答案:

答案 0 :(得分:0)

您无法在ReadLine()文件中使用playgroundSee this

所以你的行:if let input = readLine(),value = Int(input)没有执行,因此你的第二维数组不会被填充。

您可以将代码更改为这样,以查看差异:

if let input = readLine(),value = Int(input)
{
    array[row].append(value)
} else {
    array[row].append(Int(arc4random_uniform(2)))
}