Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspecting the contents of an array in the Xcode debugger

Let's say I create an array:

NSArray *newArray = [NSArray arrayWithObjects:@"foo", @"bar", @"sdfsf", nil];

In Xcode, when I stop at a breakpoint and inspect newArray I see that it says "3 Objects", yet when I click the disclosure triangle all I see is one NSObject and there seems to be no way to see what that array contains.

In practice I am working with an array of custom objects and it is a royal pain to see the nesting or inspect the properties of them.

Can anyone provide some insight on a better way to use this?

like image 440
Hippocrates Avatar asked Apr 26 '12 16:04

Hippocrates


People also ask

How do I view an array in Xcode?

As of Xcode 10, you can right-click velocity , choose "View value as..." and then "Custom Type". Then cast it to (double(&)[100]) *velocity and display the array in the GUI. This works!

How do I inspect a variable in Xcode?

Click the disclosure triangles to explore instance variables for classes and structures, or internals for other data types. Select a variable and click the Quick Look button to see a preview of the variable, click the Print Description button to print a description of the object in the console.

Does Xcode have a debugger?

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 you evaluate expressions in Xcode?

Use the po command in the Debug area Set up a breakpoint on the relevant area of code, then when the program stops at the breakpoint, enter commands in the Console in the Debug Area. The relevant command is po (print object) followed by the expression you want to evaluate.


1 Answers

If it is in scope you can just type

po newArray 

into the debugger and it will print the description.

Or if you prefer clicking things then just right click the object in the left panel pof the console and then click "Print Description of ..."

like image 136
Paul.s Avatar answered Nov 15 '22 18:11

Paul.s