swiftxcodeswiftuiexc-bad-instruction

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


I am new in SwiftUI and I am currently developing my first big application.The program runs successfully in the simulator however the simulator screen is all white and I get the error:

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

in the AppDelegate(to which I have made no changes) the app already consists of multiple files , however I can not find any problems in my code however many times I check it. What type of error should I be looking for?


Solution

  • In the context of Swift code,

    EXC_BAD_INSTRUCTION

    usually means you’ve hit a compiler trap, that is, an undefined instruction inserted into the code by the compiler because of a bug detected at runtime. The most common cause of these are: failure to unwrap an optional —

    1. This can be a forced unwrap (!) or an implicit unwrap (accessing an implicitly unwrapped optional that’s nil).
    2. array out of bounds
    3. a failed forced cast (as!), either because the value was a nil optional or because the value was of the wrong type

    You can debug this issue by creating a exception breakpoint. As the name suggests, this stops the code execution before the execution of the line that throwed this exception.

    To Create a exception breakpoint in Xcode, Go to BreakPoint navigator -> Click the + icon at the bottom left corner -> Select Exception Breakpoint.

    More about breakpoints check this link