Debug Bar in iOS6 App Development

When you build and run your apps for iOS6 with breakpoints in Xcode, the Debug bar appears in the Workspace window as the program runs in the Simulator. The program stops executing at the first breakpoint (if you have set a condition, it stops executing if that condition is met).

To control the execution, you use the Debug bar (located at the top of the Debug area that you see in the figure). The Debug bar includes buttons to

  • Open or close the Debug area. As mentioned previously, you can hide the Debug area if you don’t need it for what you’re doing right now.

  • Pause or resume execution of your code. Click this button to stop your program from executing or continue execution after it stopped when it entered the debugger.

  • Step over. Click this button to make the process counter (PC), which is identified by the green arrow in the gutter, move to the next line of code to be executed. If that line of code sends a message, it will send the message (and run the method) — but then, from your perspective, it just moves to the next line of code.

  • Step in. Click this button to move the process counter to the next line of code to be executed. If the line of code sends a message to a method in your source code, the debugger will step to the method and then return to the next line of code after the line that sends the message.

  • Step out. Click this button to step out of the current function or method. The Source editor then displays either the method that sent the message or the function’s caller.

  • Simulate location. You can have the debugger simulate the location of the iPad for you.

    image0.jpg

Because a condition was set here that the developer wanted the breakpoint to be triggered only if the networkStatus isn't equal to NotReachable, when the program ran as shown in this figure, you can see that the program has stopped executing at the breakpoint.

The networkStatus is reachableViaWiFi as you can (barely) see in the figure in the Variables pane. If you then want to watch what happens as the app executes step-by-step, you would select Step In, and the screen shown appears.

image1.jpg

You can see that the instruction

if (networkStatus == NotReachable) {

caused the debugger to move to the line following the code block that would have been executed if the if statement evaluated to YES and the debugger has paused at the blank line.

That’s because the if statement evaluated to NO — the networkStatus was reachableViaWiFi — and the code block was skipped:

  if (networkStatus == NotReachable) {
    UIAlertView *alert = [[UIAlertView alloc] 
       initWithTitle:@"Network Unavailable"
       message:@"RoadTrip requires an Internet connection" 
       delegate:nil
       cancelButtonTitle:@"OK" 
       otherButtonTitles:nil];
    [alert show];
  } 

Of course you knew that, having displayed the value of the networkStatus as reachable.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com