NSData 方法

时间:2023-02-05 22:58:58

/****************Immutable Data****************/

@interface NSData : NSObject <NSCopying, NSMutableCopying, NSSecureCoding>

- (NSUInteger)length;

- (constvoid *)bytes NS_RETURNS_INNER_POINTER;

@end

@interface NSData (NSExtendedData)

- (NSString *)description;

- (void)getBytes:(void *)buffer length:(NSUInteger)length;

- (void)getBytes:(void *)buffer range:(NSRange)range;

- (BOOL)isEqualToData:(NSData *)other;

- (NSData *)subdataWithRange:(NSRange)range;

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;

- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically; // the atomically flag is ignored if the url is not of a type the supports atomic writes

- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)writeOptionsMask error:(NSError **)errorPtr;

- (BOOL)writeToURL:(NSURL *)url options:(NSDataWritingOptions)writeOptionsMask error:(NSError **)errorPtr;

- (NSRange)rangeOfData:(NSData *)dataToFind options:(NSDataSearchOptions)mask range:(NSRange)searchRange NS_AVAILABLE(10_6, 4_0);

@end

@interface NSData (NSDataCreation)

+ (id)data;

+ (id)dataWithBytes:(const void *)bytes length:(NSUInteger)length;

+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;

+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;

+ (id)dataWithContentsOfFile:(NSString *)path options:(NSDataReadingOptions)readOptionsMask error:(NSError **)errorPtr;

+ (id)dataWithContentsOfURL:(NSURL *)url options:(NSDataReadingOptions)readOptionsMask error:(NSError **)errorPtr;

+ (id)dataWithContentsOfFile:(NSString *)path;

+ (id)dataWithContentsOfURL:(NSURL *)url;

- (id)initWithBytes:(const void *)bytes length:(NSUInteger)length;

- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;

- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;

- (id)initWithContentsOfFile:(NSString *)path options:(NSDataReadingOptions)readOptionsMask error:(NSError **)errorPtr;

- (id)initWithContentsOfURL:(NSURL *)url options:(NSDataReadingOptions)readOptionsMask error:(NSError **)errorPtr;

- (id)initWithContentsOfFile:(NSString *)path;

- (id)initWithContentsOfURL:(NSURL *)url;

- (id)initWithData:(NSData *)data;

+ (id)dataWithData:(NSData *)data;

@end