ios-学习篇-归档
归档只要将某个类实现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,归档
1.这里只记录一些学习笔记
2.这里只记录一些学习心得,如果心得方向有错,请留言
2.这里只记录一些日记(只为提升英语,暂时有点忙,等转行了开始写)