runtime归档接档(保存模型)

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
//-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    
   self = [super init];
    if (self) {
        unsigned int count = 0;
        Ivar *varList = class_copyIvarList([self class], &count);
        for (int i =0; i
   Person *p = [[Person alloc]init];
    p.name = @"武带";
    p.age = 24;
    p.sex = 1;
    
    
    
    NSString *temp = NSTemporaryDirectory();
    NSString *fileTemp = [temp stringByAppendingString:@"person.archive"];
    [NSKeyedArchiver archiveRootObject:p toFile:fileTemp];
    

    
    id data1 =  [NSKeyedUnarchiver unarchiveObjectWithFile:fileTemp];

你可能感兴趣的:(runtime归档接档(保存模型))