1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // YOUPAILCServiceInfo.m
- // LiveChat
- //
- // Created by 张灿 on 2018/4/11.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCServiceInfo.h"
- @implementation YOUPAILCServiceInfo
- - (id) initWithCoder: (NSCoder *)decoder
- {
- if (self = [super init]) {
- unsigned int count = 0;
- //获取类中所有成员变量名
- Ivar *ivar = class_copyIvarList([YOUPAILCServiceInfo class], &count);
- for (int i = 0; i<count; i++) {
- Ivar iva = ivar[i];
- const char *name = ivar_getName(iva);
- NSString *strName = [NSString stringWithUTF8String:name];
- //进行解档取值
- id value = [decoder decodeObjectForKey:strName];
- //利用KVC对属性赋值
- if(value){
- [self setValue:value forKey:strName];
- }
- }
- free(ivar);
- }
- return self;
- }
- - (void) encodeWithCoder: (NSCoder *)encoder
- {
- unsigned int count;
- Ivar *ivar = class_copyIvarList([YOUPAILCServiceInfo class], &count);
- for (int i=0; i<count; i++) {
- Ivar iv = ivar[i];
- const char *name = ivar_getName(iv);
- NSString *strName = [NSString stringWithUTF8String:name];
- //利用KVC取值
- id value = [self valueForKey:strName];
- [encoder encodeObject:value forKey:strName];
- }
- free(ivar);
- }
- @end
|