Why is Xcode's Variables View's "Edit Value" not changing the variable value? Why is Xcode's Variables View's "Edit Value" not changing the variable value? xcode xcode

Why is Xcode's Variables View's "Edit Value" not changing the variable value?


Most Swift entities, for sure strings but even "simple" types like Int's, are actually not simple types. The values you see in the Variables View are constructed by data formatters in lldb that are set up to present a useful view of the Values without running any code (for performance reasons.) They know how grub around & fetch the contents of Swift types, but we didn't teach them how to edit values, only present them.

If you want to change a value, you need to run some code in your program to do that, which you can do using the expression command in the lldb console. So for instance if you have an Int variable called foo, you can do:

(lldb) expr foo = 12

That will compile & execute that code fragment, and of course the Swift compiler does know how to alter these Swift values, so the resultant code will correctly set the value.

Note, it does appear that the swift compiler will sometimes copy a value to a register and use it from the register w/o indicating that fact in the debug info. If that happens, lldb will report the value it set in the location the debug information pointed to, but the code will actually use the temporary value. I've filed a bug with the swift compiler demonstrating one instance of this.


In case of constant Integers, you can't directly set anything.

However let's say you have variable passed as a parameter to your function:

value = (AnyObject!) Int64(38) instance_type = (Builtin.RawPointer) 0xb000000000000263

Note that this address starting with 1 is not a real pointer. Now let's say you want to replace value 38 with 64. You type:

po Unmanaged.passUnretained(64).toOpaque()and you've got magical pseudo address of constant 64:

0xb000000000000403 - _rawValue : (Opaque Value)

then you replace 0xb000000000000263 with 0xb000000000000403 and you've got your constant changed.

God, I love Swift