I am following the code shown here : Convert hex string to long to read a long from a string. In their example, they have a hard-coded string, but in my own context have another value I am taking the string from and that value seems to change but I don't think it is supposed to. I'd like to keep the value being read at the start and as such pass a deep-copy of the string to the scanner instead.
I am aware that [string copy] and [string mutableCopy] provide a shallow copy and in NSString copy not copying? question we point out that NSString is supposed to be immutable and so the scenario where it is changing is also when its pointer changes. However I am wondering if using scanner causes issues with this premise? Could I be understanding the issue here entirely wrong? I don't think the original string is supposed to even change and yet in the debugger it is changing after a few lines.
1 NSString* pString = someIdentifier;
2
3 unsigned long long val;
4 NSScanner* scanner = [NSScanner scannerWithString: pString];
5 [scanner scanHexLongLong: &val];
6
Debug breakpoints
1 pString = @"0x12345"
4 pString = @"9876543" (not exactly a hex string)
val = "74576" (some decimal close to, but not the same as the original pString)
scanner = 0x12b45 (same a pString with 1 bit different)
5 scanner = previous pString
6 pString = 0xFFFFF
val = 0xFFFFF ( in decimal)