Why does this work? In theory, creating a mutable version of an
NSData object by referencing its original bytes using
-[NSMutableData dataWithBytesNoCopy:length:freeWhenDone:], and then modifying those bytes would result in the original immutable object being modified as well.
It is worth noting that calling
-[NSData dataWithBytesNoCopy:length:freeWhenDone:] results in both data objects having the same
byte pointer address, and that memsetting the data returned by
bytes on an immutable data object will in fact update the data that it represents.
DataTest[58994:303] original data pointer location: 0x10010a630
DataTest[58994:303] original data: <4c6f7265 6d206970 73756d20 646f6c6f 72207369 7420616d 65742c20 636f6e73 65637465 74757220 61646970 69736369 6e672065 6c69742e>
DataTest[58994:303] mutable data pointer location: 0x100201a00