直接代码:
Model 归档
@interface BModel : NSObject <NSCoding>
/**
* 对象的唯一id
*/
@property (nonatomic,strong) NSNumber *guid;
/**
* 创建时间
*/
@property(nonatomic,strong) NSString *created_at;
/**
* 对象类型
*/
@property(nonatomic,strong) NSString *object_name;
/**
* 归档
*
* @param path 路径
*
* @return 成功YES 失败NO
*/
- (BOOL)archiveRootObjectWithPath:(NSString *)path;
/**
* 解档
*
* @param path 路径
*
* @return 成功YES 失败NO
*/
- (id)unarchiveObjectWithFileWithPath:(NSString *)path;
@end
#import "BModel.h"
#import <objc/runtime.h>
@implementation BModel
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super init];
if (self) {
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([self class], &count);
for (int i = 0; i<count; i++) {
// 取出i位置对应的成员变量
I