I have the following code and I am getting an exception with it.
-[_NSInlineData replaceBytesInRange:withBytes:]: unrecognized selector sent to instance 0x6000027ff2e0' terminating with uncaught exception of type NSException
Can someone point out the issue with this?
NSMutableData *data = [[NSMutableData alloc]
initWithLength:1000];
NSMutableData *d1 =(NSMutableData *) [data
subdataWithRange:NSMakeRange(sizeof(uint8_t),10)];
uint8_t i = 10;
[d1 replaceBytesInRange: NSMakeRange(1, sizeof(uint8_t)
withBytes:&i];
subdataWithRange:returns an immutableNSDatainstance. It's a copy of the original data. If you want to replace data in that copy, without affecting your originaldataobject, you can do:If you want to modify the mutable
dataobject instead, do so directly by calculating the correct range: