In MS visual studio we just right click add watch.
How does one do this in Xcode?
As fas as i understand you would like to see when a variable is changing. For this make a breakpoint and right click on it and choose Edit Breakpoint
. A window will appear:
Make sure you choose the right action like Debugger Command
or Log Message
and check the tick down at the options Automatically continue after evaluating
. So you get some kind of action (e.g. logging, sound, etc) and wont stop at the breakpoint.
Gabe's answer is almost there but missing one crucial detail: Select Debugger Output . By default the bottom option is set to Target Output, so the po
command doesn't show you anything.
Here is a sandwich app from a tutorial I'm debugging:
Being an xcode newbie and coming from a MS Visual Studio Background, I wanted exactly what the OP was looking for. While playing around from reading Gabe's answer I selected Debugger Output
and got what I wanted.
Set some breakpoints in the begginning of the looping and functions. Once u click on the breakpoint(one similar to arrow) button in the editor window the "Build and debug tool" will get enabled. You can then go to the debugger by clicking the debugger icon. on the right of the debugger window variables will be visible select self->then the instance variable u r going to set watch point.Right click on that and select "watch variable".A trigger point will be set and you will be notified with the value of the variable when changed.
If you want to know when the variable changes, use a "watch":
For example, here, I've stopped at a breakpoint in viewDidLoad
, and added a "watch" for total
:
(This is Swift, but the same is true for Objective-C, too.)
Now, if I "continue" execution (), Xcode will pause whenever this property changes and I can see at what line of code total
is changing, the stack trace to get to that point, etc.
My seniors told to use NSLog(@variable)..........
po
command in the Debug areaSet 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)
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]
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.