Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

iOS Application Debugging

IOS Application Debugging


Introduction

When we make applications, we may make various mistakes, which may lead to different kinds of errors. Therefore, to fix these errors or defects, we need to debug the application.

Choose a Debugger

The debuggers in Xcode are GDB and LLDB; GDB is the default. LLDB is a debugger that is part of the LLVM open-source compiler project. You can change the debugger by editing the active scheme options.

How to Find Coding Errors?

We just need to build our application; the code is compiled by the compiler, and all messages, errors, and warnings will be displayed along with the causes of the errors so we can correct them. You can click Product and then "Analyze" to find issues that may occur in the application.

Set breakpoints

Breakpoints help us understand our application objects and help us find many defects, including different states of logic problems. We just need to click the line number to create a breakpoint. We can delete a breakpoint by clicking and dragging it. As shown below

debug_Breakpoint

When we run the application and select playVideo, the button's application will be paused, and we can analyze the state of our application. When the breakpoint is triggered, we will get an output as shown below

debug_BreakpointStop

We can easily determine which thread triggered the breakpoint. At the bottom we can see objects such as self, sender, etc., which hold the values of the corresponding objects; we can expand some of these objects to see what each of their states is.

To continue the application, we select the Continue button (the leftmost button) in the debug area, as shown below. Other options include Step Into and Step Over

Exception breakpoint

We also have exception breakpoints, which trigger the application to stop at the location where an exception occurs. By selecting the Debug Navigator and then the "+" button, we can create an exception breakpoint. The following window will be obtained

debug_ExceptionBreakpoint

Then, we need to select the "Exception Breakpoint" breakpoint, which will display the following window

debug_ExceptionBreakpointAll

What's Next?

You can Xcode 4 User Guide Learn more about debugging and other Xcode features.