快速归档解档
来源:互联网 发布:mysql ifnull 编辑:程序博客网 时间:2024/04/29 16:47
创建一个BaseModel类,所有的对象都继承这个BaseModel就可以了。附上BaseModel代码
#import "BaseModel.h"
#import <objc/runtime.h>
@implementation BaseModel
- (id)initWithCoder:(NSCoder *)aDecoder{
if (self = [superinit]) {
Class c = self.class;
while (c && c != [NSObjectclass]) {
unsigned int count = 0;
Ivar *ivars = class_copyIvarList(c, &count);
for (int i =0; i < count; i++) {
NSString *key = [NSStringstringWithUTF8String:ivar_getName(ivars[i])];
id value = [aDecoder decodeObjectForKey:key];
[self setValue:value forKey:key];
}
c = [c superclass];
free(ivars);
}
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder{
Class c = self.class;
while (c && c != [NSObjectclass]) {
unsigned int count =0;
Ivar *ivars = class_copyIvarList(c, &count);
for (int i =0; i < count; i++) {
Ivar ivar = ivars[i];
NSString *key = [NSStringstringWithUTF8String:ivar_getName(ivar)];
id value = [selfvalueForKey:key];
[aCoder encodeObject:value forKey:key];
}
c = [c superclass];
free(ivars);
}
}
@end
- 快速归档解档
- 使用runtime快速接档归档
- 归档解档
- iOS解档归档
- iOS 解档归档
- 解档与归档
- swift归档解档
- 归档解档
- 归档与解档
- ios-归档解档
- IOS利用objc/runtime和KVC——快速归档解档
- ios 归档解归档
- 归档与解归档
- 归档、解归档
- 归档与解归档
- 归档与解归档
- 归档 解归档
- Swift-归档解归档
- Android Studio jni开发
- 使Handler内部类导致内存泄露的解决方法
- 9个循环8
- python学习5
- Android之旅---广播(BroadCast)
- 快速归档解档
- android_design support library_FloatingActionButton
- 对随机10个数求和(5)
- 欢迎使用CSDN-markdown编辑器
- 预防阻塞的方法
- Android 使用Zxing生成二维码
- 软件需求分析
- 循环(3)
- TCP/NIO示例代码