DEBUGGING YOUR APPLICATIONS

Debugging your iOS applications is an essential part of your development effort. Xcode includes debugger utilities that help you trace and examine your code as you execute your application. The following sections describe some of the tips and tricks that you can employ when developing your iOS applications.

Errors

When you try to run your application, Xcode first tries to build the project before it can deploy the application onto the real device or Simulator. Any syntax errors that Xcode detects are immediately highlighted with the exclamation icons. Figure B-11 shows an Xcode-highlighted syntax error. The error within the code block is the missing brace symbol ([) for the [[UIAlertView alloc] statement.

image

FIGURE B-11

You can also click the error icon to view the error and let Xcode suggest a fix (see Figure B-12).

image

FIGURE B-12

Warnings

Because Objective-C is a case-sensitive language, a mistake often made by beginners is mixing up the capitalization for some of the method names. Consider the block of code shown in Figure B-13.

Can you spot the error? Syntactically, the statement is correct. However, one of the parameters appears with the wrong case: initwithTitle: was misspelled — it should be initWithTitle: (note the capital “W”). When you compile the ...

Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.