标签:
归档只要将某个类实现nscoding协议就可以了
eg:
//NSCoding协议方法 -(id)initWithCoder:(NSCoder *)aDecoder{ if (self=[super init]) { self.name= [aDecoder decodeObjectForKey:@"name"]; self.sex=[aDecoder decodeObjectForKey:@"sex"]; self.age=[aDecoder decodeIntegerForKey:@"age"]; } return self; } -(void)encodeWithCoder:(NSCoder *)aCoder{ NSLog(@"调用了initWithCoder:方法"); [aCoder encodeObject:self.name forKey:@"name"]; [aCoder encodeObject:self.sex forKey:@"sex"]; [aCoder encodeInteger:self.age forKey:@"age"]; } NSArray *docaa=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //归档 [NSKeyedArchiver archiveRootObject:p toFile:[docaa[0] stringByAppendingPathComponent:@"datad.d"]]; //解档 person *pp= (person *) [NSKeyedUnarchiver unarchiveObjectWithFile:[docaa[0] stringByAppendingPathComponent:@"datad.d"]];
序列化的方法,plist,userdefault,coredata,归档
标签:
原文地址:http://www.cnblogs.com/liyang31tg/p/4279838.html