自定義歸檔
<span style="font-size:12px;">#pragma mark 自定義歸檔
-(void)custom
{
User *user = [[User alloc] init];
user.name = @"gaobo";
NSString *home = NSHomeDirectory();
NSString *path = [home stringByAppendingPathComponent:@"custom.info"];
BOOL success = [NSKeyedArchiver archiveRootObject:user toFile:path];
if (success) {
NSLog(@"自定義歸檔成功");
}else{
NSLog(@"自定義歸檔失敗");
}
}</span>
<span style="font-size:12px;">#pragma mark 自定義解歸檔
-(void)readUserInfo
{
NSString *home = NSHomeDirectory();
NSString *path = [home stringByAppendingPathComponent:@"custom.info"];
User *user = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
if (user.name) {
NSLog(@"%@",user.name);
}else{
NSLog(@"沒值");
}
}</span>