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.
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)")
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With