Watch Expression in Xcode
Asked Answered
C

2

7

Say I am debugging. Say I need to know what the value of [somevariable count]

How would I do so?

Capuche answered 25/4, 2011 at 14:24 Comment(6)
Your title and question are a bit at odds. Do you want to know the value of the expression at some point in time? Or do you want to do expression watching?Deepfreeze
possible duplicate of Where is the expression window in Xcode 4?Oralee
I want to know the value of the expression at some point in time. The answer given in the other thread seems to be something along breaking when a value change or something.Capuche
Thomas I want to do the former. The answer on the duplicate is for the latter.Capuche
Also it seems that right clicking the local variable directory and add expression works. I wonder why no body answered that.Capuche
You can follow my answer for a Swift usage: https://mcmap.net/q/380180/-where-is-the-expression-window-in-xcode-4Allsopp
D
10

If what you want to do is know the value of the expression while program execution is halted, then do something like

> p (int)[somevariable count] 

in the gdb console.

Note: People searching for the term "watch" might be expecting an answer about being able to observe when a value changes. For that question these are some answers that are more appropriate:

Watching variables in Xcode

Xcode LLDB watchpoints

Deepfreeze answered 25/4, 2011 at 14:52 Comment(1)
Alternatively in the variables view, right click and Add Expression and enter (int)[somevariable count] (the type specifier is important or your expression will never show a value)Youngran
C
3

Put a breakpoint on the relevant code line. When Xcode stops on that line, in the debug area (the bottom of the screen is splitted to two parts, look at the right one, if you don't see the bottom part, shift+cmd+Y, plus sometimes the right side or the left side are hidden and there are small buttons on the right bottom side to show them), you see all of the local and global variables. Right click (or two fingers) that debug area, and you will see a context menu with one of the options "add expression". Type in your expression.

Note: above previous user's comment about the word "watch" is pretty clear to whomever comes from any other IDE but not in Xcode.

Characterization answered 7/9, 2016 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.