数据归档
保存数据,编码(数据模型里面使用)
-(void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_name forKey:@"name"];
[aCoder encodeObject:_phoneNo forKey:@"phoneNo"];
}
读取数据,解码(数据模型里面使用)
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
_name = [aDecoder decodeObjectForKey:@"name"];
_phoneNo = [aDecoder decodeObjectForKey:@"phoneNo"];
}
return self;
}
保存数据到文档目录里面的plist文件
[NSKeyedArchiver archiveRootObject:self.contractArray toFile:self.path];
读取数据从文档目录里面的plist文件
_contractArray = [NSKeyedUnarchiver unarchiveObjectWithFile:self.path];