Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights
Reserved.
NSMutableData
Inherits From: NSData : NSObject
Conforms To: NSCoding, NSCopying, NSMutableCopying (NSData)
NSObject (NSObject)
Declared In: Foundation/NSData.h
Foundation/NSSerialization.h
Class Description
The NSMutableData class declares the programmatic interface to objects that
contain modifiable data in the form of bytes. This class inherits all read-only
access methods from its superclass, NSData, and declares only those methods
that permit the modification of the data.
NSMutableData's two primitive methodsmutableBytes and
setLength:provide the basis for all the other methods in its
interface. The mutableBytes method returns a pointer for writing into
the bytes contained in the mutable data object. setLength: allows you to
truncate or extend the length of a mutable data object.
The appendBytes:length: and appendData: methods let you append
bytes or the contents of another data object to a mutable data object. You can
replace a range of bytes in a mutable data object with either zeroes (using the
resetBytesInRange: method), or with different bytes (using the
replaceBytesInRange:withBytes: method).
This class declares various serialization methods that enable
architecture-independent serialization of arbitrary Objective C types.
Creating an NSMutableData Object
- + (id)allocWithZone:(NSZone *)zone Creates and returns an
uninitialized mutable data object from zone.
- + (id)dataWithCapacity:(unsigned int)numBytes Creates and returns
a mutable data object, initially allocating enough memory to hold
numBytes bytes.
- + (id)dataWithLength:(unsigned int)length Creates and returns a
mutable data object, giving it enough memory to hold length bytes.
Fills the object with zeroes up to length.
- - (id)initWithCapacity:(unsigned int)capacity Initializes a newly
allocated mutable data object, giving it enough memory to hold capacity
bytes. Sets the length of the data object to 0.
- - (id)initWithLength:(unsigned int)length Initializes a newly
allocated mutable data object, giving it enough memory to hold length
bytes. Fills the object with zeroes up to length.
Adjusting Capacity
- - (void)increaseLengthBy:(unsigned int)extraLength Increases the
length of a mutable data object by extraLength zero-filled bytes.
- - (void *)mutableBytes Returns a pointer to the bytes in a mutable data
object, enabling you to modify the bytes.
- - (void)setLength:(unsigned int)length Extends or truncates the
length of a mutable data object by length bytes. If the mutable data
object is extended, the additional bytes are zero-filled.
Appending Data
- - (void)appendBytes:(const void *)bytes Appends length
bytes to a mutable data object from
length:(unsigned int)length the buffer bytes.
- - (void)appendData:(NSData *)other Appends the contents of the
data object other to the receiver.
Modifying Data
- - (void)replaceBytesInRange:(NSRange)aRange Replaces the
receiver's bytes located in aRange with bytes.
withBytes:(const void *)bytes Raises an NSRangeException if
aRange is not within the range of the receiver's data.
- - (void)resetBytesInRange:(NSRange)aRange Replaces the receiver's
bytes located in aRange with zeros. Raises an NSRangeException if
aRange is not within the range of the receiver's data.
Serializing Data
- - (void)serializeAlignedBytesLength:(unsigned int)length
Prepares bytes for an appendBytes:length: invocation by
serializing them. If the length of the bytes will cause extension past
the page size, this method encodes header information, creating a hole so that
all bytes in the data object are aligned on page boundaries.
- - (void)serializeDataAt:(const void *)data Serializes whatever
data element is referenced by data,
ofObjCType:(const char *)type interpreting it by the Objective C
type specifier type.
context: If the data element is an object other than an instance of
(id <NSObjCTypeSerializationCallBack>)callback NSDictionary,
NSArray, NSString, or NSData, further definition of the object can occur
through a callback from object callback. All Objective C types are
currently supported except unions and void *. Pointers refer to a
single item.
- - (void)serializeInt:(int)value Serializes the integer
value by encoding it as a character representation.
- - (void)serializeInt:(int)value Serializes the integer
value by encoding it as a character
atIndex:(unsigned int)index representation and replaces the
encoded value at the specified index in the data.
- - (void)serializeInts:(int *)intBuffer Serializes numInts
count of integers in intBuffer by
count:(unsigned int)numInts encoding each integer as a character
representation.
- - (void)serializeInts:(int *)intBuffer Serializes numInts
count of integers in intBuffer by
count:(unsigned int)numInts encoding each integer, starting at
the specified
atIndex:(unsigned int)index index, and replacing each
corresponding integer encoding serially.