当我尝试创建一个包含带有枚举的数组的数组时出现此错误。
为了更好地说明这里的代码:
let block1:Form[] = [Form.Circle, Form.Rectangle, Form.Triangle]
let block2:Form[] = [Form.Rectangle, Form.Circle, Form.Triangle]
let block3:Form[] = [Form.Rectangle, Form.Triangle, Form.Circle]
let block4:Form[] = [Form.Circle, Form.Triangle, Form.Rectangle]
let block5:Form[] = [Form.Triangle, Form.Circle, Form.Rectangle]
let block6:Form[] = [Form.Triangle, Form.Rectangle, Form.Circle]
var allBlocks:(Form[][])!
这些是保存枚举的数组,最后一个将保存这些数组。
override func didMoveToView(view: SKView) {
allBlocks = [block1, block2, block3, block4, block5, block6] //Error here
...
}
当我尝试将值分配给 allBlocks 时发生错误
如果我将代码更改为此,我不会收到错误:
let block1:Form[] = [Form.Circle, Form.Rectangle, Form.Triangle]
let block2:Form[] = [Form.Rectangle, Form.Circle, Form.Triangle]
let block3:Form[] = [Form.Rectangle, Form.Triangle, Form.Circle]
let block4:Form[] = [Form.Circle, Form.Triangle, Form.Rectangle]
let block5:Form[] = [Form.Triangle, Form.Circle, Form.Rectangle]
let block6:Form[] = [Form.Triangle, Form.Rectangle, Form.Circle]
override func didMoveToView(view: SKView) {
var allBlocks = [block1, block2, block3, block4, block5, block6] //No error
...
}
但是后来我无法在另一个地方访问 allBlocks 变量。
编辑:如果它有帮助