//方法1:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:@"hello world"];
bool ret = [data writeToFile:@"/Users/qianfeng/Desktop/d5/d2/oc5_文件归档/111.plist" atomically:YES];
if (ret) {
NSLog(@"文件归档成功");
}else{
NSLog(@"文件归档失败");
}
//方法2:
NSArray *arr1 = @[@"hello",@"world",@"feng"];
bool ret1 = [NSKeyedArchiver archiveRootObject:arr1 toFile:@"/Users/qianfeng/Desktop/d5/d2/oc5_文件归档/222.plist"];
if (ret1) {
NSLog(@"文件归档成功");
}else{
NSLog(@"文件归档失败");
}
//*****************************文件解档********************************
//+ (id)unarchiveObjectWithData:(NSData *)data;
//+ (id)unarchiveObjectWithFile:(NSString *)path;
//方法1
NSKeyedUnarchiver *obj = [NSKeyedUnarchiver unarchiveObjectWithFile:@"/Users/qianfeng/Desktop/d5/d2/oc5_文件归档/222.plist" ];
NSLog(@"%@“,obj);
//方法2:
NSData *data3 = [NSData dataWithContentsOfFile:@"/Users/qianfeng/Desktop/d5/d2/oc5_文件归档/222.plist”];
NSKeyedUnarchiver *obj = [NSKeyedUnarchiver unarchiveObjectWithData:data3];
NSLog(@"%@",obj);