views:

302

answers:

2

I'm still haven't properly learned how to use the Xcode debugger, but I was wondering if anyone has some favourite debugging tips, things you can quickly insert into code to see the state of objects. Anything which would help me get more of a grasp on the internals of Objective-c.

Mostly I rely on NSLog(@"%@", myObject) to see what's happening with myObject, or sometimes NSLog(@"%@", [myObject class]) to check that something is really the class it should be. I know that I can do both by using the debugger, but I want to try using code for the moment, before I take the leap into using a full debugger.

Do you have any similar tricks?

+1  A: 

Asserts. Lots and lots of asserts. When you assume something must be some way, assert that it is true.

Build & Analyze is the new Build. Use the Clang Static Analyzer in Snow Leopard.

There is no magic; everything on your system and in your code happens for a reason, including crashes & misbehavior.

Embrace the debugger; it is really powerful and quite easy to start using.

Greg Parker's weblog is a wonderful source for a "behind the curtains" view of how some things work: http://www.sealiesoftware.com/blog/

bbum
+2  A: 

I also use a lot of NSAsserts all around my code.
Here are 2 useful articles by Chris Hanson about NSAssert:

Another debugging technique I use often:
As Xcode does not display array contents in the debugger view, you can use the (gdb) console or the expression window to list array contents. Here is a related SO post.

weichsel