My class has a member variable which is a NSNumber, like so:
@interface C : NSObject {
NSNumber* _n;
}
During debugging, I am stopped at a breakpoint, and I want to change the value of the NSNumber. How can I do it?
I tried the XCode variables window, but that does not work.
I tried the XCode debug console, for example
expr _n = @1
but that gives the bizarre message error: assigning to 'NSNumber *' from incompatible type 'NSNumber *' -- no kidding! Try it.
I also tried
expr _n = [NSNumber numberWithInt:1]
but that gives the same thing.
This worked for me:
(lldb) expr -- _n = (NSNumber *)[NSNumber numberWithInt:123]
(NSNumber *) $0 = 0x0000000000007b83 (int)123
(lldb) po _n
(NSNumber *) $1 = 0x0000000000007b83 123
The -- is required to mark the end of command options and beginning of "raw" input.
Strictly speaking, this does not change the value of the existing NSNumber, but assigns a new NSNumber object to _n. But NSNumber objects are immutable, so changing their value is not possible anyway.
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