37

I know that might sound like a stupid question since it's a trivial feature in most modern IDEs, but I'm diving into iOS development and am getting familiar with the platform and SDK and I can't figure this out. I have a ton of experience with MS Visual Studio and I see that Xcode works very much the same, tho it's still lacking quite a bit of functionality in comparison, but still a very good IDE. When it comes to debugging, Xcode works very similar to Visual Studio in that you can hover your mouse over a variable and it will display its current value. When it comes to object variables, however, it almost always give just the address along with the expand arrow, which expands to "NSObject", which expands to "isa", which expands to all the attributes that don't tell me anything. I'm used to the IDE, like Visual Studio, being smart enough to do some introspection and display for me the actual object and all it's immediate properties and values. I'm assuming Xcode is smart enough to do this and I'm just not using it correctly.

If I set a breakpoint on a line of code that involves an object instance (lets say NSDateComponents instance), how can I view the values of its properties (i.e. year, week, day, hour, etc.)?

Thanks in advance for your help!

Edit: Here's a screenshot of the info I get with every object I inspect... alt text http://joecrotchett.com/images/misc/example.jpg

4
  • This is pretty weird. It should show you the actual data. Does it happen that way for every class? Commented Aug 11, 2010 at 17:55
  • 3
    really, this is abnormal? yeah, it happens all the time. Commented Aug 11, 2010 at 17:57
  • Does it happen for all objects or just NSDateComponents? Commented Aug 11, 2010 at 18:27
  • all objects. if someone has a chance, can they write a quick line of code that creates and inits an NSDateComponents object, debug it and post a screenshot? i'm really surprised no one knows what i'm talking about. Commented Aug 11, 2010 at 18:31

5 Answers 5

34

It's frustrating. The debugger has to know the structure of every object and it apparently doesn't. It used to be much worse, though. Like with NSArray's, they're an array of objects. The debugger doesn't know what type of objects specifically, and that's due to the Objective-C language, not the debugger.

As you dive into iOS development, I think you're going to find that Apple is about 15 years behind its competitors when it comes to development. That's no joke. But they're catching up and, trust me, it used to be much worse!

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, that's too bad. Oh well, I guess I'll go back to use a bunch of NSLog statements :( I haven't had to use the "print-to-screen" method of debugging since I wrote assembly code over ten years ago. Ok, I'll stop whining now. Thanks again!
While a good rant (I feel it too) because it ought to be automatic, it is possible to greatly improve things. The right thing to do is implement description as shown in in other answers.
5

For my data objects I tend to overwrite the description method and output a string with the summary of the object. Something like this:

Printing description of myContact:
{name=Homer, lastname=Simpson, ...}

This means that you can quickly inspect an object in the debugger or when you NSLog it to the console. If that description contains all relevant data you could also overwrite isEqual: so that it uses the description to compare two objects.

Comments

3

Hover over a variable and a line will pop up about it. Move your mouse right very slightly, and hover over the triangle arrow that's at the left side of the popup, that arrow will turn downward, and another popup will open showing all the named properties of that object.

You can also get it to print its "description" value. Move your pointer slightly right until it's over the two little "up/down" arrows. Then left (well, "main") click. A pop-up will show up and one option will be "Print description". If you click on that, it'll put the output of its -description method to the console.

4 Comments

thanks dan, but like i said, when i click the arrow on the left side of the popup, it always displays "NSObject" as the only property.
Yeah, well, see the little "uppy downy" looking arrows between the arrow and the name of the object? Click that. There'll be a "Print Description" option in there. See if that tells you anything. You can also use "po" in the console to print the description of a variable, of course...
i tried that, all it prints is "<NSDateComponents: 0xbc291a0>"
I was able to do this on Xcode 7 by clicking the little (i) ("i" in a circle), next to the eye symbol (when hovering over a variable and opening/inspecting its properties with the little triangles.) Each time i clicked the (i) the print description appeared in the console. Every property of a variable seems to have an eye symbol and an (i) symbol.
3

You can also change the way the Xcode shows a value in the local variables pane by going to "Edit Summary Format" on the right-click menu.

For example, to get it to call the description method, you would set it to

{(NSString*)[$VAR description]}:s

Few more details here: understanding Xcode debugger var display

Comments

2

Well, a couple more years have passed, and xcode still is showing isa = (Class) on most of the objects instead of be able to figure out what is the object.

And even that a couple of years have passed, Apple is still behind, because the competition is running loops around them (and they are now 16 years behind of competitores current state).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.