Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you watch or evaluate an expression in xcode like visual studio's immediate window?

Tags:

In MS visual studio we just right click add watch.

How does one do this in Xcode?

like image 929
user4951 Avatar asked Apr 14 '11 11:04

user4951


People also ask

How do you evaluate expressions in Xcode?

Evaluate a C/ObjC/C++ expression in the current program context, using user defined variables and variables currently in scope. This command takes 'raw' input (no need to quote stuff). -G <gdb-format> ( --gdb-format <gdb-format> ) Specify a format using a GDB format specifier string.

How do I show immediate window in Visual Studio?

Execute a function at design timeOn the Debug menu, choose Windows > Immediate.

How do I view a watch window in Visual Studio?

The Watch Window. The Watch Window allows you to see value of variables and expressions while debugging. It's kind of like the DataTip you get when hovering over a variable, except that you can write any expression you want. It's available from Debug | Windows | Watch | Watch 1 or Ctrl + Alt + W + 1.


1 Answers

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.

If the Debug window is not visible in XCode, you can show it via the top menu:

'View' -> 'Debug Area' -> 'Activate Console' (XCode v8.x)

Example

To evaluate an expression like var1/var2 where var1 and var2 are both doubles, enter the following in the Console:

po var1/var2 

The Console will return something like:

(double) $2 = 3.085 [no Objective-C description available] 

Showing object properties

You can also return a particular property of an object currently used in the code at that breakpoint:

po [bankInfo city] 

And it will return something like:

(id) $4 = 0x000069e8 Testville 

Note though that the Console doesn't seem to like the dot notation and prefers the square brackets when applicable. For example, this returns an error for me:

po bankInfo.city 

I hope this is what you've been looking for.

like image 100
Gabe Prime Avatar answered Apr 05 '23 12:04

Gabe Prime