Search code examples
objective-cgnustep

NSData bytes readonly?


According to the GNUstep documentation, [NSData bytes] returns const void*.

Does that mean that I'm not supposed to modify the data referenced by that pointer?

Currently I'm modifying the data, and it works for me. I can write to a file and the modified data go there.


Solution

  • NSData is unmutable by definition. Use NSMutableData instead.`

    NSMutableData *mutableData = [[NSMutableData alloc] initWithData:data];
    void *pointerToMutableBytes = [mutableData mutableBytes];