Information Technology Reference
In-Depth Information
Working with Breakpoints
A breakpoint is a deliberate pause in your code. When Xcode encounters a breakpoint, it stops and drops into a
special breakpoint mode. You can use this mode to view memory, list objects and their contents, and step
through the code line by line.
Breakpoint debugging is very powerful, but relying on it can slow you down. For maximum productivity, use
breakpoint debugging selectively, and don't assume that it's a reliable solution for every possible problem. For
example, if you don't manage memory correctly in an iOS app, memory errors can happen at almost any point
in your code. Single-step debugging can show you that an object or property has incorrect or null contents, but
it won't show you which line of code released it prematurely.
Working with simple breakpoints
To explore breakpoints, create a very simple application as a test bed. Use File⇒New in Xcode to create a new
OS X Cocoa Application and save it as BreakpointTest. Add a simple counter loop to the end of the applica-
tiondidFinishLaunching: method in the App Delegate:
for (int i = 0 ; i< 10; i++) {
NSLog(@”Count: %i”, i);
}
The code counts from 0 to 9 and logs each increment to the console. Open and resize the console window, and
then build and run the application. The result should look like Figure 15.9.
When you run the code, the count completes almost instantly. With a breakpoint, it's possible to step through
the loop manually and check what happens at each repeat.
FIGURE 15.9
Logging a very simple counter to the console
 
Search WWH ::




Custom Search