文件的归档与解档方法一atom
文件归档code
设置参数 NSArray *array=@[ @"hello",@"world",@{@"name":@"Maky"},@45]; NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/test/test.plist"]; 归档过程 NSKeyedArchiver *archiver=[NSKeyedArchiver archiveRootObject:array toFile:path];
文件解档对象
解档过程 NSArray *arrayUn=[NSKeyedUnarchiver unarchiveObjectWithFile:path];
文件的归档与解档方法二string
文件归档it
1.定义一个可变数据流NSMutableData NSMutableData *muData=[[NSMutableData alloc]init]; 2.建立一个归档类的对象 NSKeyedArchiver *archiverI=[[NSKeyedArchiver alloc]initForWritingWithMutableData:muData]; 3.归档过程 [archiverI encodeObject:array forKey:@"arrayEncode"]; 4.关闭归档 [archiverI finishEncoding]; 5.写入本地文件 [muData writeToFile:path atomically:YES];
文件解档table
1.建立一个NSData NSData *data=[[NSData alloc]initWithContentsOfFile:path]; 2.建立一个解档类的对象 NSKeyedUnarchiver *unArchiver=[[NSKeyedUnarchiver alloc]initForReadingWithData:data]; 3.解档 NSArray *arrayUnI=[unArchiver decodeObjectForKey:@"arrayEncode"]; 4.关闭解档对象 [unArchiver finishDecoding];