问题
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)
回答1:
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
A little menu will pop up, and from that, you select Exception Breakpoint…
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
回答2:
You gotta scroll up to see the error. If you scroll up above all the "terminating with uncaught exception of type NSException" stuff you will see something like "Terminating app due to blah blah blah" and then in the next line right below it will say "reason: blah blah blah". That should tell you why the app crashed.
来源:https://stackoverflow.com/questions/46408727/how-do-i-know-which-line-of-code-has-caused-my-ios-app-to-crash-in-xcode-9