4

当我尝试创建一个包含带有枚举的数组的数组时出现此错误。

为了更好地说明这里的代码:

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 变量。

编辑:如果它有帮助

4

2 回答 2

1

这听起来像是一个 Swift 编译器错误;崩溃是由于试图执行非法的 x86 指令,因此编译器生成了无效代码或生成了指向根本不是代码或不是指令开头的内容的分支。

假设您正在对 Xcode 进行 beta 测试,因此,如果您还没有 Apple Developer Connection 帐户,可以让您在 Radar^W Apple Bug Reporter上提交错误,请打开一个帐户,然后提交错误。(Apple 可能已经在 Xcode 下载中提供了这方面的详细信息。)

于 2014-06-14T19:45:24.290 回答
0

我认为这在 XCode6 beta 6 中不再是问题。这是我的测试代码:

enum Form: Int {
    case Circle=1
    case Rectangle
    case Triangle
}


func testEnumArray () {
    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 = [block1, block2, block3, block4, block5, block6]
    println(allBlocks)

}

它不再抛出异常。

此外,自问题发布以来,语法发生了变化:

而不是let block6:Form[]我们需要写let block6:[Form]

于 2014-08-28T09:05:11.133 回答