O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSMutableData — Mac OS X 10.0

Synopsis

This class adds mutable functionality to NSData, allowing the contents of the data object to be altered after initialization. NSMutableData provides two methods for adjusting the size of the underlying data buffer: increaseLengthBy:,and setLength:. The first of these increases the size of the buffer by the indicated number of bytes, while the latter sets the size of the buffer to the specified number of bytes.

Data is added to a mutable data object using either appendData: or appendBytes:length. appendData: joins the specified NSData object to the end of the receiver, while appendBytes:length: appends to the receiver the number of bytes specified in length from the buffer pointer to in the first parameter.

NSMutableData also provides replaceBytesInRange:withBytes: and replaceBytesInRange:withBytes:length: to directly alter the contents of the underlying data buffer. If you want to zero a portion of data, use the method resetBytesInRange:.

NSMutableData is toll-free bridged with the Core Foundation type CFData. As such, NSMutableData objects can be used interchangeably with the CFData pointer type, CFDataRef.

image with no caption

@interface NSMutableData : NSData
                                  // Initializers
   - (id)initWithCapacity:(unsigned)capacity;
   - (id)initWithLength:(unsigned)length;
                                  // Accessor Methods
   - (void)setData:(NSData *)data;
   - (void)setLength:(unsigned)length ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required