MyOrderModel.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // MyOrderModel.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/10/8.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "MyOrderModel.h"
  9. @implementation MyOrderModel
  10. + (NSDictionary *)modelContainerPropertyGenericClass {
  11. return @{@"orderProductList" : [MyOrderModel class],
  12. @"productList" : [MyOrderModel class],
  13. @"order" : [MyOrderModel class]
  14. };
  15. }
  16. + (NSDictionary *)modelCustomPropertyMapper {
  17. return @{@"describe" : @"description"};
  18. }
  19. - (NSArray *)arrayTypeTitle {
  20. return _arrayTypeTitle = @[@"", @"待付款", @"待发货", @"待收货", @"待评价", @"已取消", @"已完成"];
  21. // return _arrayTypeTitle = @[@"", @"待付款", @"待评价", @"已取消"];
  22. }
  23. /*
  24. 使用runtime进行解档与归档。
  25. */
  26. - (void)encodeWithCoder:(NSCoder *)aCoder {
  27. unsigned int count = 0;
  28. Ivar *ivarLists = class_copyIvarList([MyOrderModel class], &count);// 注意下面分析
  29. for (int i = 0; i < count; i++) {
  30. const char* name = ivar_getName(ivarLists[i]);
  31. NSString* strName = [NSString stringWithUTF8String:name];
  32. [aCoder encodeObject:[self valueForKey:strName] forKey:strName];
  33. }
  34. free(ivarLists); //一定不要忘了,自己释放。
  35. }
  36. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  37. if (self = [super init]) {
  38. unsigned int count = 0;
  39. Ivar *ivarLists = class_copyIvarList([MyOrderModel class], &count);
  40. for (int i = 0; i < count; i++) {
  41. const char* name = ivar_getName(ivarLists[i]);
  42. NSString* strName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
  43. id value = [aDecoder decodeObjectForKey:strName];
  44. [self setValue:value forKey:strName];
  45. }
  46. free(ivarLists);
  47. }
  48. return self;
  49. }
  50. @end