Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Xcode's Variables View, on the right of the Debug area, when an app is running and paused at a breakpoint you can right-click a variable and select "Edit Value".

For a swift String it's greyed out, and I can imagine why that might be the case. But even for a simple int, it brings up an edit box to enter an new value, but after hitting the value stays at the old value. This is true even for a var which is changed during the code.

Update: as shown in Jim's answer below, you should be able to set the value using the lldb expression command, but, although Xcode will tell you it has changed, it fails to actually change the value.

Is this broken, or is there something specific you need to do for it to work? Thanks.

Screenshot

Update: It's a compile bug - see Jim's comment. Here's a workaround...

    println("Before lldb change, foo is \(foo)")
    //make compiler think foo may change, so I can change it myself at the console
    if count("abcd") == 0 { foo = 0 }
    println("After lldb change, code now thinks foo is \(foo)")
like image 457
DenverCoder9 Avatar asked Jul 12 '15 10:07

DenverCoder9


People also ask

How do I change the value of a variable in Eclipse debugger?

Changing a Variable's Value To set a variable go to the Variables view and select the variable you want to change. Right click on the variable and select Change Value... Once you have change the value click ok. The variable now has a new value.

How do I change variable value in runtime?

To change a variable's value, just double-click it, and enter a new value. For example, to change the value in loopIndex from 3 to 2 , double-click loopIndex in the Variables view, enter 2 in the dialog that opens (shown in Figure 5-24), and click OK.

Is it possible to change the value of a variable while debugging in application?

Yes u can if you have the authorization: while debugging do a doubleclick on the variable, the system'll show the name and the value of the variable, change the value and press CHANGE icon.


1 Answers

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

like image 144
user1232690 Avatar answered Oct 06 '22 05:10

user1232690