I get this error when I try to create an array which contain arrays with enums.
To illustrate better here's the code:
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[][])!
These are the arrays holding the enums and the last one will hold these arrays.
override func didMoveToView(view: SKView) {
allBlocks = [block1, block2, block3, block4, block5, block6] //Error here
...
}
The error occurs when I try to assign the value to allBlocks
If I change the code to this I get no error:
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
...
}
But then I can't access the allBlocks variable in another place.
EDIT: In case it helps
This sounds like a Swift compiler bug; the crash was due to an attempt to execute an illegal x86 instruction, so either the compiler generated invalid code or generated a branch to something that wasn't code at all or wasn't the beginning of an instruction.
Presumably you're beta-testing Xcode, so, if you don't already have an Apple Developer Connection account that lets you file bugs on Radar^WApple Bug Reporter, open an account, and then file a bug. (Apple may have given details on this as part of the Xcode download.)
I think it is no longer an issue in XCode6 beta 6. Here is my test code:
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)
}
It does not throw exception anymore.
In addition, there is a syntax change since the question was posted:
Instead of let block6:Form[]
we need to write let block6:[Form]
来源:https://stackoverflow.com/questions/24223321/exc-bad-instruction-code-exc-i386-invop-subcode-0x0-on-swift-when-working-wit