Using Breakpoints

Many developers use NSLog() for logging to the console.  There is an easier way to do the same using breakpoints.  When you use NSLog(), you have to go through your code and comment out each line that is printing to the console if you want to disable logging.  It is much easier to disable all breakpoints at the same time.

To create a breakpoint, click in the gutter next to the line you are interested in.  Then right-click on the breakpoint and click on Edit Breakpoint…  

After that click on the Add Action button.

You can add as many actions as you need with the + and – buttons.  For example you can add a log message “my method called”.  Then you can add a debugger command that prints the values of some of your variables in that method.  In most cases you would want to check the option Automatically continue after evaluation.  This will not stop your app when the breakpoint is reached.

To give you an example.  I have created a single view application.  In the viewDidLoad: method I have  declared an NSString *myString.  If I want to log when that particular method is called and print the value of the string I will need to set up a breakpoint with the following actions.

Consult the LLDB debugger documentation to see what can be done with the debugger command.

To disable or enable all the breakpoints in your project.  Go to the Breakpoint Navigator (command+6), right-click on the project name and disable or enable the breakpoints.