Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 624
BeachRunnerFred Avatar asked Aug 11 '10 17:08

BeachRunnerFred


People also ask

How do I show variables in Xcode?

When you find your variable, right-click on it and choose “Watch”. Once that's done you can continue your program as normal, and anywhere the variable is read from or written to Xcode will pause and you can use the debug navigator to step through the call stack to figure out what happened.

How do I show variables in debug mode?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I display output in Xcode?

If you just want to have the log output display when you run your app then you can go into XCode4 preferences -> Alerts and click on 'Run starts' on the left hand column. Then select 'Show Debugger' and when you run the app the NSLog output will be displayed below the editor pane.

How do I show debugger in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.


1 Answers

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!

like image 89
beeeefy Avatar answered Sep 24 '22 16:09

beeeefy