iosswiftexc-bad-instruction

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error loading from Bundle


I'm making a calc just for fun and I want to add a sound for when you press a button.

The error is:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

On this line of code:

let alertSound = URL(fileURLWithPath: Bundle.main.path(forResource: "219069_annabloom_click1", ofType: "wav")!)

Solution

  • I think the problem at here

     let alertSound = URL(fileURLWithPath: Bundle.main.path(forResource: "219069_annabloom_click1", ofType: "wav")!)
    

    meaning of this sign is ! the value is not nil. But I think you have't added the file correctly or there is issue with .wav extension double check it so it returns nil and app is crashed.

    Step 1: make sure you have added sound file correctly

    Step 2: verify extension is same in code and file

    make sure the module is selected

    enter image description here