iosswiftdebuggingsigabrtnsexception

How do I know which line of code has caused my iOS app to crash in Xcode 9


I am building an app in Xcode 9 (Swift 4) and it crashes before it even loads completely. I get an error: Thread 1: Signal SIGABRT and libc++abi.dylib: terminating with uncaught exception of type NSException. How do I know which line of code is causing the error using breakpoints and debugging? Any help would be appreciated. Thanks! (Here's a screenshot as well)enter image description here


Solution

  • What you need here is an exception breakpoint. An exception breakpoint is a special kind of breakpoint that breaks whenever an exception occurs, instead of on a specific line in a specific file every time. The line where the breakpoint breaks is the line that throws the exception. To set an exception breakpoint, you'll need to open the breakpoint navigator and press the + button in the bottom left

    Xcode breakpoint navigator

    A little menu will pop up, and from that, you select Exception Breakpoint…

    Exception Breakpoint option

    A 3rd menu might pop up afterwards, but you can just click anywhere outside of it to dismiss it. After that, when you build and run your app again, it will break whenever an exception is thrown on the line that it is thrown