Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding Xcode debugger var display

Tags:

xcode

newbie question: can anyone tip me to how to understand/interpret what is displayed in the debugger var pane?

Ex: I am passing an NSDictionary as a method param. I set a breakpoint so I can examine the values in the dictionary. The image below (if it comes through..) shows the expanded view of this var in the debugger. It correctly reports that it contains 3 name/value pairs but as I expand all the sections, I simply can not find where these are stored.

Do I have to create local vars of these name/value pairs in order to view them when I want to check? I know I can use NSLog or printf but sometimes I just want a quick peek.

dictionary var in debugger

like image 233
spring Avatar asked Oct 13 '11 18:10

spring


People also ask

How do I find the value of a variable in Xcode?

See Variable Values in Code and the Variable Viewer When your app pauses at a breakpoint, hover over a variable in your source code to view its current value. If the variable is an image or other type that isn't expressible as text, click the Quick Look button at the upper-right to see a preview of the variable.

How do I debug a variable 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.

How do I see local variables in Xcode?

Right click in the local variables window to see the "Watch Expression" menu command. Type the variable name and the variable will be added.

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.


1 Answers

Right click the variable, click "Edit Summary Format" and type the following:

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

This replaces the GDB formatter for NSDictionary with a call to the more expensive description method.
That is, instead "x key/value pairs", you'll see the contents of the dictionary as produced by -[NSDictionary description].

This is the same as typing po dictionary in the console window. Or right clicking the variable and choosing "Print Description". Both of them call the description method of the object.


If you are curious, you can find this formatter at /Developer/Library/Xcode/CustomDataViews/Foundation.plist under the key NSDictionary. What you type as replacement is saved in /Users/USERNAME/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters and will persist across runs until you delete that file.

A NSDictionary is really a class cluster and few people know the inside structure. At this point you ain't going to find much use for that debugger tree.

like image 78
Jano Avatar answered Sep 18 '22 13:09

Jano