【发布时间】:2016-04-13 16:37:05
【问题描述】:
我在 Swift 中遇到了数组问题,我想创建一个这样的数组:
var Test : [[String]] = [[]]
let test_string = "HELLO"
for var i = 0; i <= 15; ++i {
for x in test_string.characters {
Test[i].append("\(i)\(x)")
}
}
print(Test[1][1]) // This should print 1E
但这总是给我这个错误! :
fatal error: Array index out of range
我在这里缺少什么?
【问题讨论】:
-
你没有在
Test上追加任何东西,执行Test[i].append("\(i)\(x)")时没有Test[0]