文件的歸檔與解檔方法一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];