Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I quickly inspect the value of an arbitrary variable in Xcode 4.6.x?

It seems reasonably widely acknowledged that it is slow to use the po command in Xcode 4.6.x. What are the options for inspecting the values of arbitrary variables unspecified at compile time (which rules out usage of NSLog()) which don't take > 15s?

like image 325
NSTJ Avatar asked Apr 13 '13 13:04

NSTJ


People also ask

How to see variable values 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 to watch a variable 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.


2 Answers

Just set a breakpoint where you want to learn the variables' value. Once the program is paused, a summary of all the variables' value will appear on the Varibles view on the left-bottom of the screen. Here is a screenshot :

enter image description here

like image 58
Moray Avatar answered Sep 22 '22 05:09

Moray


You can use the lldb commands:

p (int) myInt
po myObject
po myObject.memberObject
p (float) myObject.floatMember

Just a note, you could also use p instead of po in the newest version of Xcode. If you run the help -a in llb, it will present you with command aliases, below is a snippet of the commands you could use.

> (lldb) help -a  
p         -- ('expression --')  Evaluate a C/ObjC/C++ expression in the current
         program context, using user defined variables and variables
         currently in scope.  

po        -- ('expression -o  --')  Evaluate a C/ObjC/C++ expression in the
         current program context, using user defined variables and
         variables currently in scope  

print     -- ('expression --')  Evaluate a C/ObjC/C++ expression in the current
         program context, using user defined variables and variables
         currently in scope.
like image 41
user352891 Avatar answered Sep 18 '22 05:09

user352891