1, NSData
Comments:
The type of data used to store the binary
The NSData class provides a simple way to set a buffer, read the contents of a file into a buffer, or write the contents of a buffer to a file.
Invariant buffers (NSData classes), or variable buffers (Nsmutabledata classes) can also be defined.
NSData, NSString Mutual transfer:
NSData * data = [str datausingencoding:nsutf8stringencoding]; NSString Convert to NSData type
NSString * Newstr = [[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];
NSData, Byte transfer
NSString *teststring = @ "1234567890";
NSData *testdata = [teststring datausingencoding:nsutf8stringencoding];
byte *testbyte = (BYTE *) [testData bytes];
Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
NSData *adata = [[NSData alloc] Initwithbytes:byte length:24];
NSData Turn UIImage
UIImage *aimage = [UIImage imagewithdata:data];
NSData Turn Nsdictionary
@interface Nsdictionary (Helpers)
+ (Nsdictionary *) Dictionarywithcontentsofdata: (NSData *) data;
@end
@implementation Nsdictionary (Helpers)
+ (Nsdictionary *) Dictionarywithcontentsofdata: (NSData *) Data {
Cfpropertylistref plist = Cfpropertylistcreatefromxmldata (Kcfallocatordefault, (cfdataref) data,
Kcfpropertylistimmutable,
NULL);
if (plist = = nil) return nil;
if ([(ID) plist Iskindofclass:[nsdictionary class]]) {
return [(Nsdictionary *) plist autorelease];
}
else {
Cfrelease (plist);
return nil;
}
}
@end
NSData Application Scenarios
Reads the contents of a file into a memory buffer
NSData *fileData;
< Span class= "PLN" > nsfilemanager *filemanager = [[ Nsfilemanager Alloc]init
< Span class= "PLN" >< Span class= "pun" >< Span class= "PLN" > filedata = [filemanager contentsatpath:path
/span> writes the contents of the buffer to a file
nsfilemanager *filemanager = [[nsfilemanager Alloc ]init];
[filemanager Createfileatpath:path contents:fileData Attributes:nil];
< Span class= "PLN" >< Span class= "pun" >< Span class= "PLN" >< Span class= "PLN" >< Span class= "pun" >< Span class= "pun" > World article a big copy of the content according to the following blog finishing
Http://www.cnblogs.com/GISerYang/p/3345350.html
http://bj007.blog.51cto.com/1701577/538990/
http://blog.csdn.net/jerryvon/article/details/7350567
Http://www.cnblogs.com/duchengdong/archive/2012/03/29/2422997.html
IOS Basic Data Type-nsdata