Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode evaluating expressions while debugging

I am working on an iPhone app. I am a full-time Java developer and I am used to using Eclipse where I can put a breakpoint in and stop the process. Then, I can type in any expression that I want and Eclipse will evaluate it using the values from that point in the process.

Is there a way to do that in Xcode? I want to be able to stop at a breakpoint and then enter some code to evaluate it. The gdb console will let me do po (print-object), but it is really limited. Any help?

like image 225
Christopher Martin Avatar asked Jan 28 '11 06:01

Christopher Martin


People also ask

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.

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.

How do I use symbolic breakpoints in Xcode?

You can click on Breakpoint Navigator and click on + symbol at the bottom and select Symbolic Breakpoint as an option. Now, you can ask - This is fine for putting a break on simple variables.

How do I debug in Xcode step by step?

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.


2 Answers

In XCode 4.0 this is sort of hidden in the GUI. When you're at a breakpoint you can probably see the Variables View inside the Debug Area; it's the pane which shows local variables and such. Right-click on the Variables View and select "Add Expression..."

I realize this is an old thread but it's still a top Google hit so I thought it worth answering.

like image 94
Belden Fox Avatar answered Oct 13 '22 05:10

Belden Fox


My practice:

po [NSUserDefaults standardUserDefaults]

displays: <NSUserDefaults: 0x6143040>

po [[NSUserDefaults standardUserDefaults] stringForKey:@"Currency"]

displays: "CHF"

like image 30
Peter Avatar answered Oct 13 '22 04:10

Peter