对数据对象进行归档和取消
对数据对象进行归档
View Code
对数据取消归档
View Code
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:myObject forKey:@"keyValueString"];
[archiver finishEncoding];
BOOL seccess = [data writeToFile:@"/path/to/archive" atomically:YES];
[archiver release];
[data release];
success为YES,表示成功
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:myObject forKey:@"keyValueString"];
[archiver finishEncoding];
BOOL seccess = [data writeToFile:@"/path/to/archive" atomically:YES];
[archiver release];
[data release];
success为YES,表示成功
对数据取消归档
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSKeyedArchiver *unarchiver = [[NSKeyedUnArchiver alloc] initForReadingWithData:data];
//解读对象
self.object = [unarchiver decoderObjectForKey:@"keyValueString"];
[unarchiver finishDecoding];
[unarchiver release];
[data release];
NSKeyedArchiver *unarchiver = [[NSKeyedUnArchiver alloc] initForReadingWithData:data];
//解读对象
self.object = [unarchiver decoderObjectForKey:@"keyValueString"];
[unarchiver finishDecoding];
[unarchiver release];
[data release];