ios development of NSData

NSData for storing an array of bytes. 

Initialization

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

initialize the object. 
Byte array copy operation is not performed, directly byte pointer bytes, length for length. 

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

initialize the object. 
Byte array copy operation is not performed, directly byte pointer bytes, length for length. 

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

initialize the object. 
Copy byte array, a pointer to the copy of the set of bytes byte array, length for length. 

- (Nullable instanceType) initWithContentsOfFile: (NSString * ) path;
 

read the contents of the file to initialize the object. 
Reading success, it returns the object, if it fails, it returns nil.

- (Nullable instanceType) initWithContentsOfFile: (NSString *) path Options: (NSDataReadingOptions) readOptionsMask error: (NSError ** ) errorPtr;
 

read the contents of the file to initialize the object. 
Read successfully object is returned. If it fails it returns nil, the error message is stored in errorPtr in. 
ReadOptionsMask parameter specifies the file read option. 

NS_OPTIONS typedef (NSUInteger, NSDataReadingOptions) { 
    NSDataReadingMappedIfSafe =    1UL << 0 , 
    NSDataReadingUncached = 1UL << . 1 ,    
    NSDataReadingMappedAlways   = 1UL << . 3 , 

    NSDataReadingMapped = NSDataReadingMappedIfSafe, 
    NSMappedRead =NSDataReadingMapped, 
    NSUncachedRead = NSDataReadingUncached 
};
 
- (Nullable instanceType) initWithContentsOfURL: (NSURL * ) url; 

read content url initialize the object. 
Reading success, it returns the object, if it fails, it returns nil. 

- (Nullable instanceType) initWithContentsOfURL: (NSURL *) url Options: (NSDataReadingOptions) readOptionsMask error: (NSError ** ) errorPtr; 

read url contents initialize the object. 
Read successfully object is returned. If it fails it returns nil, the error message is stored in errorPtr in. 
ReadOptionsMask parameter specifies the file read option. 

- (instanceType) initWithData: (NSData * ) Data;
 

initialization NSData object according to the object. 

- (Nullable the above mentioned id ) initWithContentsOfMappedFile: (NSString * ) path 

to initialize the object based on the file content. Read the contents of the file is not the way the read system call, but mmap system call. 

Construction

 +(instancetype) data; 

configured empty NSData object. 

+ (InstanceType) :( dataWithBytesNoCopy void * ) bytes length: (NSUInteger) length freeWhenDone: (BOOL) B;
 

the object is constructed according to an array of bytes. Byte array is not copied. 

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

the object is constructed according to an array of bytes. Byte array is not copied. 

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

the object is constructed according to an array of bytes. Copy the byte array. 

 + (Nullable instanceType) dataWithContentsOfFile: (NSString * ) path;
 

construct an object based on the file contents. 

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

construct an object based on the file contents. 

 + (Nullable instanceType) dataWithContentsOfURL: (NSURL * ) url;
 

the object is constructed in accordance with the content url. 

+ (Nullable instanceType) dataWithContentsOfURL: (NSURL *) url Options: (NSDataReadingOptions) readOptionsMask error: (the NSError ** ) errorPtr;
 

the object is constructed in accordance with the content url. 

+ (InstanceType) dataWithData: (NSData * ) Data;
 

configured NSData object according to the object. 

+ (Nullable the above mentioned id ) dataWithContentsOfMappedFile: (NSString * ) path
 

object is constructed according to the filing. Read the contents of the file is not the way the read system call, but mmap system call. 

Returns the length 

@Property ( Readonly ) NSUInteger length;
 

return data 

@Property ( Readonly ) const  void *bytes
 

return data in the interval

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

Parameters buffer to store the retrieved data, parameters specified range data acquisition interval. 

- ( void ) :( the getBytes void * ) Buffer length: (NSUInteger) length;
 

get data specified length. If the length is greater than the data length, the data length is used as the designated length. 

- ( void ) getBytes :( void * ) Buffer
 

get all the data. 

Intercept the data

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

parameter range specified interval taken. 

Are equal to

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

if data equality comparison. 

Write to file

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

parameter specifies the file path path. ErrorPtr parameters stored in the write failure error message. Represents writeOptionsMask parameter options when writing files, use or operator connection. With the possible values 

typedef NS_OPTIONS (NSUInteger, NSDataWritingOptions) { 
NSDataWritingAtomic = 1UL << 0 , 
NSDataWritingWithoutOverwriting NS_ENUM_AVAILABLE (10_8, 6_0) = 1UL << . 1 , 

NSDataWritingFileProtectionNone NS_ENUM_AVAILABLE_IOS (4_0)   = 0x10000000 , 
NSDataWritingFileProtectionComplete NS_ENUM_AVAILABLE_IOS (4_0)   = 0x20000000 ,
NS_ENUM_AVAILABLE_IOS NSDataWritingFileProtectionCompleteUnlessOpen (5_0)   = 0x30000000 , 
NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication NS_ENUM_AVAILABLE_IOS (5_0)   = 0x40000000 , 
NSDataWritingFileProtectionMask NS_ENUM_AVAILABLE_IOS (4_0)   = 0xF0000000 , 
NSAtomicWrite = NSDataWritingAtomic      
}; 

NSDataWritingAtomic represents the atoms completing a file using the auxiliary operations. 
NSDataWritingWithoutOverwriting represents preventing overwrite an existing file, can not be combined with NSDataWritingAtomic. 

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

write to a file. Parameters path specify a file path, file parameters useAuxiliaryFile auxiliary atomic operation is completed. 

Write url

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

Parameters path specified url path. ErrorPtr parameters stored in the write failure error message. WriteOptionsMask optional parameter indicates the time of writing, can be used or operator connection. 

- (BOOL) writeToURL: (NSURL * ) to atomically around URL: (BOOL) to atomically around;
 

write url. Parameters path specify a file path, the parameter atomically atomic operation is completed. 

Search

 - (NSRange) rangeOfData: (NSData * ) DataToFind Options: (NSDataSearchOptions) mask the Range: (NSRange) searchRange
 

search data. DataToFind parameters for the data search. SearchRange parameters for the search range. The parameter mask for the search. Search mode may be used or operator connection. 
Search methods are: 

typedef NS_OPTIONS (NSUInteger, NSDataSearchOptions) { 
    NSDataSearchBackwards = 1UL << 0 , 
    NSDataSearchAnchored =1UL << . 1 
} 


NSDataSearchBackwards searches forward from the rear. 
NSDataSearchAnchored represents just search for the head or tail (used in conjunction with NSDataSearchBackwards). 

Base64 encoding related

 - (Nullable instanceType) initWithBase64EncodedString: (NSString * ) base64String Options: (NSDataBase64DecodingOptions) Options
 

decoded string. options for the decoding mode. 

NS_OPTIONS typedef (NSUInteger, NSDataBase64DecodingOptions) { 
    NSDataBase64DecodingIgnoreUnknownCharacters = 1UL << 0 
} NS_ENUM_AVAILABLE (10_9, 7_0); 


NSDataBase64DecodingIgnoreUnknownCharacters represents ignore unknown characters. 

- (NSString * ) base64EncodedStringWithOptions: (NSDataBase64EncodingOptions) Options
 

encoded as a string. Parameter options for the encoding.

typedef NS_OPTIONS(NSUInteger, NSDataBase64EncodingOptions) {
    NSDataBase64Encoding64CharacterLineLength = 1UL << 0,
    NSDataBase64Encoding76CharacterLineLength = 1UL << 1,
    NSDataBase64EncodingEndLineWithCarriageReturn = 1UL << 4,
    NSDataBase64EncodingEndLineWithLineFeed = 1UL << 5,

} NS_ENUM_AVAILABLE(10_9, 7_0);


- (nullable instancetype)initWithBase64EncodedData:(NSData *)base64Data options:(NSDataBase64DecodingOptions)options


解码数据。

- (NSData *) base64EncodedDataWithOptions: (NSDataBase64EncodingOptions) options
 

encoded data. 

- (Nullable ID ) initWithBase64Encoding: (NSString * ) base64String
 

decoded string. 

- (NSString * ) base64Encoding
 

encoded as a string. 
NSMutableData variable for storing an array of bytes. 

Return data 

@Property ( Readonly ) void * mutableBytes
 

returns the length 

@property NSUInteger length; 

initialize

 - (Nullable instanceType) initWithCapacity: (NSUInteger) Capacity;
 

matches the size of the object is initialized. 

- (Nullable instanceType) initWithLength: (NSUInteger) length;
 

the length of the object is initialized. An array of all cleared to 0. 

Construction

  +(nullable instancetype) dataWithCapacity: (NSUInteger
 ) aNumItems; 

matches the size of the constructed object. 

 + (Nullable instanceType) dataWithLength: (NSUInteger) length;
 

The length of the constructed object. 

Add

 - ( void ) appendBytes :( const  void * ) bytes length: (NSUInteger) length;
 

Adds an array. 

- ( void ) appendData: (NSData * ) OTHER; 

add data. 

Alternatively

 - ( void ) replaceBytesInRange: (NSRange) :( Range withBytes const  void * ) bytes;
 

replacement byte array. 

- ( void ) replaceBytesInRange: (NSRange) the Range withBytes: (Nullable const  void* ) ReplacementBytes length: (NSUInteger) replacementLength;
 

replacement byte array. Alternatively replacementLength parameter specifies the length of the array. 

Increasing the length of

 - ( void ) increaseLengthBy: (NSUInteger) extraLength;
 

Reset

 - ( void ) resetBytesInRange: (NSRange) Range;
 

internal reset interval data is 0. 

Settings

 - ( void ) the setData: (NSData *) Data;

 

Guess you like

Origin www.cnblogs.com/Free-Thinker/p/11412165.html