开发者

How can I view the values inside an object in the Xcode debugger?

开发者 https://www.devze.com 2023-01-11 07:55 出处:网络
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 fi

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 bi开发者_JAVA百科t 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


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!


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.


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.


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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消