EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, subcode = 0x0) in Swift when working with multidimensional arrays

I get this error when I try to create an array containing enumerated arrays.

To better illustrate 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 arrays containing enumerations, and the latter will contain these arrays.

 override func didMoveToView(view: SKView) { allBlocks = [block1, block2, block3, block4, block5, block6] //Error here ... } 

The error occurs when I try to set the value of allBlocks

If I change the code to this, I will not get an 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 elsewhere.

EDIT: in case this helps

+4
source share
2 answers

This sounds like a Swift compiler error; the accident was caused by an attempt to execute an illegal x86 instruction, so either the compiler generated the wrong code, or generated a branch to the fact that there was no code at all or was not the beginning of the instruction.

You are supposedly a beta test of Xcode, so if you do not already have an Apple Developer Connection account that allows you to create errors on Radar ^ W Apple Bug Reporter , open an account and then report an error. (Apple may have talked about this as part of the Xcode download.)

+1
source

I think this 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) } 

No longer throws an exception.

In addition, there is a syntax change since the question was sent:

Instead of let block6:Form[] we need to write let block6:[Form]

0
source

Source: https://habr.com/ru/post/971287/


All Articles