YOUPAILZBadgeModel.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // YOUPAILZBadgeModel.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/9/6.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBadgeModel.h"
  9. @implementation YOUPAILZBadgeModel
  10. - (instancetype)init
  11. {
  12. self = [super init];
  13. if (self) {
  14. }
  15. return self;
  16. }
  17. - (id) initWithCoder: (NSCoder *)decoder
  18. {
  19. if (self = [super init]) {
  20. unsigned int count = 0;
  21. //获取类中所有成员变量名
  22. Ivar *youpaipivar = class_copyIvarList([YOUPAILZBadgeModel class], &count);
  23. for (int i = 0; i<count; i++) {
  24. Ivar iva = youpaipivar[i];
  25. const char *name = ivar_getName(iva);
  26. NSString *strName = [NSString stringWithUTF8String:name];
  27. //进行解档取值
  28. id value = [decoder decodeObjectForKey:strName];
  29. //利用KVC对属性赋值
  30. if(value){
  31. [self setValue:value forKey:strName];
  32. }
  33. }
  34. free(youpaipivar);
  35. }
  36. return self;
  37. }
  38. - (void) encodeWithCoder: (NSCoder *)encoder
  39. {
  40. unsigned int count;
  41. Ivar *youpaipivar = class_copyIvarList([YOUPAILZBadgeModel class], &count);
  42. for (int i=0; i<count; i++) {
  43. Ivar iv = youpaipivar[i];
  44. const char *name = ivar_getName(iv);
  45. NSString *strName = [NSString stringWithUTF8String:name];
  46. //利用KVC取值
  47. id value = [self valueForKey:strName];
  48. [encoder encodeObject:value forKey:strName];
  49. }
  50. free(youpaipivar);
  51. }
  52. + (NSDictionary *)mj_replacedKeyFromPropertyName
  53. {
  54. return @{
  55. @"youpaipuser_id":@"user_id",
  56. @"youpaipid":@"id",
  57. @"youpaipname":@"name",
  58. @"youpaipfile":@"file",
  59. @"youpaippreview_img":@"preview_img",
  60. @"youpaipbig_preview_img":@"big_preview_img",
  61. @"youpaipwidth":@"width",
  62. };
  63. }
  64. @end