NSData | Mac OS X 10.0 |
This class is used to store immutable data as a string of bytes. In essence, NSData is an Objective-C wrapper around a C data buffer. To access the buffer directly, use the bytes method, which returns a pointer to the buffer. The number of bytes contained in the buffer is found by invoking the length method. Additionally, NSData provides a handful of methods for copy bytes from the data object into a buffer. These methods include getBytes:, getBytes:length:, and getBytes:range:. All three of these methods take in the first parameter a generic C pointer to the buffer in which the bytes are copied.
NSData is toll-free bridged with the Core Foundation type CFData. As such, NSData objects can be used interchangeably with the CFData pointer type, CFDataRef.
Note that NSData is an immutable class, which means the contents of the data object cannot be changed after initialization.
@interface NSData : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
// Convenience Constructors |
+ (id)data;
|
+ (id)dataWithBytes:(const void *)bytes length:(unsigned)length; |
+ (id)dataWithBytesNoCopy:(void *)bytes length:(unsigned)length; |
+ (id)dataWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)b; |
+ (id)dataWithContentsOfFile:(NSString *)path; |
+ (id)dataWithContentsOfMappedFile:(NSString *)path; |
+ (id)dataWithContentsOfURL:(NSURL *)url; |
+ (id)dataWithData:(NSData *)data; |
// Initializers |
- (id)initWithBytes:(const void *)bytes length:(unsigned)length; |
- (id)initWithBytesNoCopy:(void *)bytes length:(unsigned)length; |
- (id)initWithBytesNoCopy:(void *)bytes length:(unsigned)length freeWhenDone:(BOOL)b; |
- (id)initWithContentsOfFile:(NSString *)path; |
- (id)initWithContentsOfMappedFile:(NSString *)path; |
- (id)initWithContentsOfURL:(NSURL *)url; |
- (id)initWithData:(NSData *)data; |
// Instance Methods |
- (const void *)bytes;
|
- (NSString *)description;
|
- (unsigned)deserializeAlignedBytesLengthAtCursor:(unsigned *)cursor; |
- (void)deserializeBytes:(void *)buffer length:(unsigned)bytes atCursor:(unsigned *)cursor; |
- (void)deserializeDataAt:(void *)data ofObjCType:(const char *)type atCursor:(unsigned *)cursor context:(id <NSObjCTypeSerializationCallBack>)callback; |
- (int)deserializeIntAtCursor:(unsigned *)cursor; |
- (int)deserializeIntAtIndex:(unsigned)index; |
- (void)deserializeInts:(int *)intBuffer count:(unsigned)numInts atCursor:(unsigned *)cursor; |
- (void)deserializeInts:(int *)intBuffer count:(unsigned)numInts atIndex:(unsigned)index; |
- (void)getBytes:(void *)buffer; |
- (void)getBytes:(void *)buffer length:(unsigned)length; |
- (void)getBytes:(void *)buffer range:(NSRange)range; |
- (BOOL)isEqualToData:(NSData *)other; |
- (unsigned)length;
|
- (NSData *)subdataWithRange:(NSRange)range; |
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile; |
- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically; |
// Methods Implementing NSCoding |
- (void)encodeWithCoder:(NSCoder *)aCoder; |
- (id)initWithCoder:(NSCoder *)aDecoder; |
// Methods Implementing NSCopying |
- (id)copyWithZone:(NSZone *)zone; |
// Methods Implementing NSMutableCopying |
- (id)mutableCopyWithZone:(NSZone *)zone; |
NSMutableData