YOUPAILCUserModel.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // YOUPAILCUserModel.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/4/11.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCUserModel.h"
  9. @implementation YOUPAILCUserModel
  10. - (id) initWithCoder: (NSCoder *)decoder
  11. {
  12. if (self = [super init]) {
  13. unsigned int count = 0;
  14. //获取类中所有成员变量名
  15. Ivar *ivar = class_copyIvarList([YOUPAILCUserModel class], &count);
  16. for (int i = 0; i<count; i++) {
  17. Ivar iva = ivar[i];
  18. const char *name = ivar_getName(iva);
  19. NSString *strName = [NSString stringWithUTF8String:name];
  20. //进行解档取值
  21. id value = [decoder decodeObjectForKey:strName];
  22. //利用KVC对属性赋值
  23. if(value){
  24. [self setValue:value forKey:strName];
  25. }
  26. }
  27. free(ivar);
  28. }
  29. return self;
  30. }
  31. - (void) encodeWithCoder: (NSCoder *)encoder
  32. {
  33. unsigned int count;
  34. Ivar *ivar = class_copyIvarList([YOUPAILCUserModel class], &count);
  35. for (int i=0; i<count; i++) {
  36. Ivar iv = ivar[i];
  37. const char *name = ivar_getName(iv);
  38. NSString *strName = [NSString stringWithUTF8String:name];
  39. //利用KVC取值
  40. id value = [self valueForKey:strName];
  41. [encoder encodeObject:value forKey:strName];
  42. }
  43. free(ivar);
  44. }
  45. + (NSDictionary *)mj_replacedKeyFromPropertyName
  46. {
  47. return @{
  48. @"youpaipuserinfo":@"userinfo",
  49. @"youpaipserviceInfo":@"serviceInfo",
  50. };
  51. }
  52. @end