Class

NSMutableData

An object representing a dynamic byte buffer in memory.

Declaration

@interface NSMutableData : NSData

Overview

NSMutableData and its superclass NSData provide data objects, or object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects. They are typically used for data storage and are also useful in Distributed Objects applications, where data contained in data objects can be copied or moved between applications. NSData creates static data objects, and NSMutableData creates dynamic data objects. You can easily convert one type of data object to the other with the initializer that takes an NSData object or an NSMutableData object as an argument.

The following NSData methods change when used on a mutable data object:

When called, the bytes are immediately copied and then the buffer is freed.

NSMutableData is “toll-free bridged” with its Core Foundation counterpart, CFDataRef. See Toll-Free Bridging for more information on toll-free bridging.

Topics

Creating Mutable Data

+ dataWithCapacity:

Creates and returns a mutable data object capable of holding the specified number of bytes.

+ dataWithLength:

Creates and returns an mutable data object containing a given number of zeroed bytes.

- initWithCapacity:

Returns an initialized mutable data object capable of holding the specified number of bytes.

- initWithLength:

Initializes and returns a mutable data object containing a given number of zeroed bytes.

Accessing Raw Bytes

mutableBytes

A pointer to the data contained by the mutable data object.

Counting Bytes

length

The number of bytes contained in the mutable data object.

Adding Bytes

- appendBytes:length:

Appends to the receiver a given number of bytes from a given buffer.

- appendData:

Appends the content of another data object to the receiver.

- increaseLengthBy:

Increases the length of the receiver by a given number of bytes.

Modifying Bytes

- replaceBytesInRange:withBytes:

Replaces with a given set of bytes a given range within the contents of the receiver.

- replaceBytesInRange:withBytes:length:

Replaces with a given set of bytes a given range within the contents of the receiver.

- resetBytesInRange:

Replaces with zeroes the contents of the receiver in a given range.

- setData:

Replaces the entire contents of the receiver with the contents of another data object.

Relationships

Inherits From

See Also

Binary Data

NSData

A static byte buffer in memory.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software