Chapter 19. Ten Debugging Tips
In This Chapter
Checking for semicolons
Watching for lower- versus uppercase terms
Paying attention to the first syntax error
Recognizing the usefulness of compiler warnings
Looking for memory errors
Knowing your debugger's features
Checking for messages to
nilSending messages to the right object
Using
NSLogTesting incrementally
Solving logic errors
When you're developing an application, there are always a few things that initially don't work out quite the way you planned. That means you will have to go through your code and determine what happened, and more importantly, what to do about it.
Check for Semicolons
Semicolons are the heart and soul of Objective-C statements, and leaving one out can cause incredible havoc. For some reason, forgetting to end a statement with one is something I'm pretty good at. So when I see a lot of errors and warnings, especially if I've just added a few lines of code, semicolons are one of the first things I check.
"Right" Is Not Always "right"
Remember, Objective-C is case-sensitive and For is not the same thing as for. Using the wrong case can send the complier into a tizzy, and while you will get warnings and errors, what you have done may not always be obvious.
When You've Blown It, You've Blown It
It's generally better to ignore the subsequent errors after the first syntax error because they may be the result of that first error. This is especially true when you leave out #import statements (or spell them wrong) or forget a semicolon ...