- (IBAction)saveBtnClick:(id)sender {
NJStudent *stu = [[NJStudent alloc] init];
stu.name = @"lnj";
stu.age = 28;
stu.height = 1.8;
stu.weight = 60;
// 2.获取文件路径
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [docPath stringByAppendingPathComponent:@"stu.xxoo"];
NSLog(@"path = %@", path);
// 3.将自定义对象保存到文件中
[NSKeyedArchiver archiveRootObject:stu toFile:path];
- (IBAction)readBtnClick:(id)sender {
// 1.获取文件路径
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [docPath stringByAppendingPathComponent:@"stu.xxoo"];
// 2.从文件中读取对象
NJStudent *stu = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSLog(@"%@ %d %.1f %.1f", stu.name, stu.age, stu.height, stu.weight);
}