标签:
1.在people类中对属性进行序列化.添加<NSCoding>
//编码 -(void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.name forKey:@"name"]; } //解码 -(id)initWithCoder:(NSCoder *)aDecoder { self=[super init]; if (self) { self.name=[aDecoder decodeObjectForKey:@"name"]; } return self; }
2.序列化与反序列化
people *p=[[people alloc]init]; p.name=@"tom"; NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/1.txt"]; //归档 [NSKeyedArchiver archiveRootObject:p toFile:path]; // people *p1=[NSKeyedUnarchiver unarchiveObjectWithFile:path]; NSLog(@"%@",p1.name);
标签:
原文地址:http://www.cnblogs.com/kyuubee/p/4830807.html