MyModel.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // MyModel.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/9/26.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "MyModel.h"
  9. @implementation MyModel
  10. + (NSDictionary *)modelCustomPropertyMapper {
  11. return @{@"headimgurl" : @"userLogo",
  12. @"wxHeadImgUrl" : @"headimgurl"
  13. };
  14. }
  15. - (NSMutableArray *)arrayData {
  16. if (!_arrayData) {
  17. _arrayData = @[
  18. @[@""],
  19. @[
  20. @{@"title": @"同行阅读动态", @"titleImage": @"005", @"detail": @""},
  21. @{@"title": @"学习报告", @"titleImage": @"009", @"detail": @""}],
  22. @[
  23. @{@"title": @"作者认证", @"titleImage": @"006", @"detail": @""},
  24. @{@"title": @"我的论文", @"titleImage": @"004", @"detail": @""},
  25. @{@"title": @"账户", @"titleImage": @"007", @"detail": @""}],
  26. @[
  27. @{@"title": @"我的会员", @"titleImage": @"001", @"detail": @""},
  28. @{@"title": @"分享", @"titleImage": @"分享", @"detail": @""}],
  29. @[
  30. @{@"title": @"设置", @"titleImage": @"003", @"detail": @""}]].mutableCopy;
  31. }
  32. return _arrayData;
  33. }
  34. - (NSMutableArray *)achievementList {
  35. if (!_achievementList) {
  36. _achievementList = @[].mutableCopy;
  37. }
  38. return _achievementList;
  39. }
  40. /*
  41. 使用runtime进行解档与归档。
  42. */
  43. - (void)encodeWithCoder:(NSCoder *)aCoder {
  44. unsigned int count = 0;
  45. Ivar *ivarLists = class_copyIvarList([MyModel class], &count);// 注意下面分析
  46. for (int i = 0; i < count; i++) {
  47. const char* name = ivar_getName(ivarLists[i]);
  48. NSString* strName = [NSString stringWithUTF8String:name];
  49. [aCoder encodeObject:[self valueForKey:strName] forKey:strName];
  50. }
  51. free(ivarLists); //一定不要忘了,自己释放。
  52. }
  53. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  54. if (self = [super init]) {
  55. unsigned int count = 0;
  56. Ivar *ivarLists = class_copyIvarList([MyModel class], &count);
  57. for (int i = 0; i < count; i++) {
  58. const char* name = ivar_getName(ivarLists[i]);
  59. NSString* strName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
  60. id value = [aDecoder decodeObjectForKey:strName];
  61. [self setValue:value forKey:strName];
  62. }
  63. free(ivarLists);
  64. }
  65. return self;
  66. }
  67. @end