MOLiveCenterData.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // MOLiveCenterData.m
  3. //
  4. // Created by SuperCabbage on 2023/12/6
  5. // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOLiveCenterData.h"
  8. #import "MOUserBase.h"
  9. NSString *const kMOLiveCenterDataMembers = @"members";
  10. NSString *const kMOLiveCenterDataTicketGoldenBean = @"ticketGoldenBean";
  11. NSString *const kMOLiveCenterDataPopularity = @"popularity";
  12. NSString *const kMOLiveCenterDataGiftGoldenBean = @"giftGoldenBean";
  13. NSString *const kMOLiveCenterDataOtherGoldenBean = @"otherGoldenBean";
  14. NSString *const kMOLiveCenterDataFans = @"fans";
  15. NSString *const kMOLiveCenterDataViewerNum = @"viewerNum";
  16. NSString *const kMOLiveCenterDataMvpUser = @"mvpUser";
  17. NSString *const kMOLiveCenterDataLikeGoldenBean = @"likeGoldenBean";
  18. NSString *const kMOLiveCenterDataDivideGoldenBean = @"divideGoldenBean";
  19. @interface MOLiveCenterData ()
  20. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  21. @end
  22. @implementation MOLiveCenterData
  23. @synthesize members = _members;
  24. @synthesize ticketGoldenBean = _ticketGoldenBean;
  25. @synthesize popularity = _popularity;
  26. @synthesize giftGoldenBean = _giftGoldenBean;
  27. @synthesize otherGoldenBean = _otherGoldenBean;
  28. @synthesize fans = _fans;
  29. @synthesize viewerNum = _viewerNum;
  30. @synthesize mvpUser = _mvpUser;
  31. @synthesize likeGoldenBean = _likeGoldenBean;
  32. @synthesize divideGoldenBean = _divideGoldenBean;
  33. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  34. return [[self alloc] initWithDictionary:dict];
  35. }
  36. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  37. self = [super init];
  38. // This check serves to make sure that a non-NSDictionary object
  39. // passed into the model class doesn't break the parsing.
  40. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  41. self.members = [[self objectOrNilForKey:kMOLiveCenterDataMembers fromDictionary:dict] doubleValue];
  42. self.ticketGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataTicketGoldenBean fromDictionary:dict] doubleValue];
  43. self.popularity = [[self objectOrNilForKey:kMOLiveCenterDataPopularity fromDictionary:dict] doubleValue];
  44. self.giftGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataGiftGoldenBean fromDictionary:dict] doubleValue];
  45. self.otherGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataOtherGoldenBean fromDictionary:dict] doubleValue];
  46. self.fans = [[self objectOrNilForKey:kMOLiveCenterDataFans fromDictionary:dict] doubleValue];
  47. self.viewerNum = [[self objectOrNilForKey:kMOLiveCenterDataViewerNum fromDictionary:dict] doubleValue];
  48. self.mvpUser = [MOUserBase modelObjectWithDictionary:[dict objectForKey:kMOLiveCenterDataMvpUser]];
  49. self.likeGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataLikeGoldenBean fromDictionary:dict] doubleValue];
  50. self.divideGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataDivideGoldenBean fromDictionary:dict] doubleValue];
  51. }
  52. return self;
  53. }
  54. - (NSDictionary *)dictionaryRepresentation {
  55. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  56. [mutableDict setValue:[NSNumber numberWithDouble:self.members] forKey:kMOLiveCenterDataMembers];
  57. [mutableDict setValue:[NSNumber numberWithDouble:self.ticketGoldenBean] forKey:kMOLiveCenterDataTicketGoldenBean];
  58. [mutableDict setValue:[NSNumber numberWithDouble:self.popularity] forKey:kMOLiveCenterDataPopularity];
  59. [mutableDict setValue:[NSNumber numberWithDouble:self.giftGoldenBean] forKey:kMOLiveCenterDataGiftGoldenBean];
  60. [mutableDict setValue:[NSNumber numberWithDouble:self.otherGoldenBean] forKey:kMOLiveCenterDataOtherGoldenBean];
  61. [mutableDict setValue:[NSNumber numberWithDouble:self.fans] forKey:kMOLiveCenterDataFans];
  62. [mutableDict setValue:[NSNumber numberWithDouble:self.viewerNum] forKey:kMOLiveCenterDataViewerNum];
  63. [mutableDict setValue:[self.mvpUser dictionaryRepresentation] forKey:kMOLiveCenterDataMvpUser];
  64. [mutableDict setValue:[NSNumber numberWithDouble:self.likeGoldenBean] forKey:kMOLiveCenterDataLikeGoldenBean];
  65. [mutableDict setValue:[NSNumber numberWithDouble:self.divideGoldenBean] forKey:kMOLiveCenterDataDivideGoldenBean];
  66. return [NSDictionary dictionaryWithDictionary:mutableDict];
  67. }
  68. - (NSString *)description {
  69. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  70. }
  71. #pragma mark - Helper Method
  72. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  73. id object = [dict objectForKey:aKey];
  74. return [object isEqual:[NSNull null]] ? nil : object;
  75. }
  76. #pragma mark - NSCoding Methods
  77. - (id)initWithCoder:(NSCoder *)aDecoder {
  78. self = [super init];
  79. self.members = [aDecoder decodeDoubleForKey:kMOLiveCenterDataMembers];
  80. self.ticketGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataTicketGoldenBean];
  81. self.popularity = [aDecoder decodeDoubleForKey:kMOLiveCenterDataPopularity];
  82. self.giftGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataGiftGoldenBean];
  83. self.otherGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataOtherGoldenBean];
  84. self.fans = [aDecoder decodeDoubleForKey:kMOLiveCenterDataFans];
  85. self.viewerNum = [aDecoder decodeDoubleForKey:kMOLiveCenterDataViewerNum];
  86. self.mvpUser = [aDecoder decodeObjectForKey:kMOLiveCenterDataMvpUser];
  87. self.likeGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataGiftGoldenBean];
  88. self.divideGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataDivideGoldenBean];
  89. return self;
  90. }
  91. - (void)encodeWithCoder:(NSCoder *)aCoder
  92. {
  93. [aCoder encodeDouble:_members forKey:kMOLiveCenterDataMembers];
  94. [aCoder encodeDouble:_ticketGoldenBean forKey:kMOLiveCenterDataTicketGoldenBean];
  95. [aCoder encodeDouble:_popularity forKey:kMOLiveCenterDataPopularity];
  96. [aCoder encodeDouble:_giftGoldenBean forKey:kMOLiveCenterDataGiftGoldenBean];
  97. [aCoder encodeDouble:_otherGoldenBean forKey:kMOLiveCenterDataOtherGoldenBean];
  98. [aCoder encodeDouble:_fans forKey:kMOLiveCenterDataFans];
  99. [aCoder encodeDouble:_viewerNum forKey:kMOLiveCenterDataViewerNum];
  100. [aCoder encodeObject:_mvpUser forKey:kMOLiveCenterDataMvpUser];
  101. [aCoder encodeDouble:_likeGoldenBean forKey:kMOLiveCenterDataLikeGoldenBean];
  102. [aCoder encodeDouble:_divideGoldenBean forKey:kMOLiveCenterDataDivideGoldenBean];
  103. }
  104. - (id)copyWithZone:(NSZone *)zone {
  105. MOLiveCenterData *copy = [[MOLiveCenterData alloc] init];
  106. if (copy) {
  107. copy.members = self.members;
  108. copy.ticketGoldenBean = self.ticketGoldenBean;
  109. copy.popularity = self.popularity;
  110. copy.giftGoldenBean = self.giftGoldenBean;
  111. copy.otherGoldenBean = self.otherGoldenBean;
  112. copy.fans = self.fans;
  113. copy.viewerNum = self.viewerNum;
  114. copy.mvpUser = [self.mvpUser copyWithZone:zone];
  115. copy.likeGoldenBean = self.likeGoldenBean;
  116. copy.divideGoldenBean = self.divideGoldenBean;
  117. }
  118. return copy;
  119. }
  120. @end