Why can I print a variable that "doesn't exist"

(lldb) p index

(Int) 2

(lldb) watchpoint set variable index

error: no variable or instance variable named 'index' found in this frame

index is a @State variable. If I list variables, there is _index, with a value of 0. It seems that it's a default value. Clearly lldb is sourcing the value of index from somewhere?

My code is getting fed the right values, so clearly index is getting changed.

How can I watch this variable 'index' that is actually changing?

Just in case you are not aware of it, index is a computed property generated by @State property wrapper. It appears lldb watchpoint command only support monitoring value at a specific memory address (my quick search shows gdb watch command supports monitoring expression by single stepping).

Oh wait, is index then a computed property? So watchpoint set expression index might work?

I guess so. What's the result? I'm curious to know too.

Try _index.wrappedValue.