Finding Where Your App Crashes in Xcode
March 20th, 2017
As you’re developing an app, it may crash when you run it. When it crashes you want to know where the crash occurs so you can fix the error that’s causing the crash. Set an exception breakpoint in Xcode to find your project crashes.
Setting an Exception Breakpoint
Go to Xcode’s breakpoint navigator by choosing View > Navigators > Show Breakpoint Navigator. At the bottom of the breakpoint navigator is an Add (+) button. Click the Add button and choose Exception Breakpoint. The exception breakpoint is initially set to fire on all exceptions.
Now when you run your app in Xcode, Xcode will pause the app when it crashes, allowing you to locate the line of code where the crash occurs.
One thing to keep in mind with exceptions is they can fire for reasons other than a crash. As an example Xcode throws an exception every time you save with Core Data, even if there are no problems with the save. Disable the exception breakpoint when it annoys you. Enable the exception breakpoint when your app crashes.
Sharing the Breakpoint
Setting an exception breakpoint is something you want for most projects. Xcode lets you share breakpoints so you don’t have to create them every time you create a new project. Exception breakpoints and test failure breakpoints are the most common breakpoints to share.
There are two ways to share a breakpoint. First, select the breakpoint in the breakpoint navigator, right-click, and choose Share Breakpoint.
Second, you can make a user breakpoint that is available for every project in your Mac user account. Select the breakpoint in the breakpoint navigator, right-click, and choose Move Breakpoint To > User.