VideoCourseModel.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // VideoCourseModel.m
  3. //
  4. // Created by Steven on 2024/11/21
  5. // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "VideoCourseModel.h"
  8. NSString *const kVideoCourseModelId = @"id";
  9. NSString *const kVideoCourseModelLessonCoverUrl = @"lessonCoverUrl";
  10. NSString *const kVideoCourseModelRealName = @"realName";
  11. NSString *const kVideoCourseModelLessonCount = @"lessonCount";
  12. NSString *const kVideoCourseModelMusicNum = @"musicNum";
  13. NSString *const kVideoCourseModelAuditVersion = @"auditVersion";
  14. NSString *const kVideoCourseModelLessonSubjectName = @"lessonSubjectName";
  15. NSString *const kVideoCourseModelLessonDesc = @"lessonDesc";
  16. NSString *const kVideoCourseModelLessonPrice = @"lessonPrice";
  17. NSString *const kVideoCourseModelCountStudent = @"countStudent";
  18. NSString *const kVideoCourseModelLessonName = @"lessonName";
  19. NSString *const kVideoCourseModelAvatar = @"avatar";
  20. NSString *const kVideoCourseModelLessonSubject = @"lessonSubject";
  21. NSString *const kVideoCourseModelPayType = @"payType";
  22. NSString *const kVideoCourseModelTeacherId = @"teacherId";
  23. NSString *const kVideoCourseModelRelationType = @"relationType";
  24. NSString *const kVideoCourseModelUserName = @"userName";
  25. NSString *const kVideoCourseModelVirtualNumber = @"virtualNumber";
  26. @interface VideoCourseModel ()
  27. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  28. @end
  29. @implementation VideoCourseModel
  30. @synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
  31. @synthesize lessonCoverUrl = _lessonCoverUrl;
  32. @synthesize realName = _realName;
  33. @synthesize lessonCount = _lessonCount;
  34. @synthesize musicNum = _musicNum;
  35. @synthesize auditVersion = _auditVersion;
  36. @synthesize lessonSubjectName = _lessonSubjectName;
  37. @synthesize lessonDesc = _lessonDesc;
  38. @synthesize lessonPrice = _lessonPrice;
  39. @synthesize countStudent = _countStudent;
  40. @synthesize lessonName = _lessonName;
  41. @synthesize avatar = _avatar;
  42. @synthesize lessonSubject = _lessonSubject;
  43. @synthesize payType = _payType;
  44. @synthesize teacherId = _teacherId;
  45. @synthesize relationType = _relationType;
  46. @synthesize userName = _userName;
  47. @synthesize virtualNumber = _virtualNumber;
  48. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
  49. {
  50. return [[self alloc] initWithDictionary:dict];
  51. }
  52. - (instancetype)initWithDictionary:(NSDictionary *)dict
  53. {
  54. self = [super init];
  55. // This check serves to make sure that a non-NSDictionary object
  56. // passed into the model class doesn't break the parsing.
  57. if(self && [dict isKindOfClass:[NSDictionary class]]) {
  58. self.internalBaseClassIdentifier = [self objectOrNilForKey:kVideoCourseModelId fromDictionary:dict];
  59. self.lessonCoverUrl = [self objectOrNilForKey:kVideoCourseModelLessonCoverUrl fromDictionary:dict];
  60. self.realName = [self objectOrNilForKey:kVideoCourseModelRealName fromDictionary:dict];
  61. self.lessonCount = [[self objectOrNilForKey:kVideoCourseModelLessonCount fromDictionary:dict] doubleValue];
  62. self.musicNum = [[self objectOrNilForKey:kVideoCourseModelMusicNum fromDictionary:dict] integerValue];
  63. self.auditVersion = [self objectOrNilForKey:kVideoCourseModelAuditVersion fromDictionary:dict];
  64. self.lessonSubjectName = [self objectOrNilForKey:kVideoCourseModelLessonSubjectName fromDictionary:dict];
  65. self.lessonDesc = [self objectOrNilForKey:kVideoCourseModelLessonDesc fromDictionary:dict];
  66. self.lessonPrice = [[self objectOrNilForKey:kVideoCourseModelLessonPrice fromDictionary:dict] doubleValue];
  67. self.countStudent = [[self objectOrNilForKey:kVideoCourseModelCountStudent fromDictionary:dict] doubleValue];
  68. self.lessonName = [self objectOrNilForKey:kVideoCourseModelLessonName fromDictionary:dict];
  69. self.avatar = [self objectOrNilForKey:kVideoCourseModelAvatar fromDictionary:dict];
  70. self.lessonSubject = [self objectOrNilForKey:kVideoCourseModelLessonSubject fromDictionary:dict];
  71. self.payType = [self objectOrNilForKey:kVideoCourseModelPayType fromDictionary:dict];
  72. self.teacherId = [self objectOrNilForKey:kVideoCourseModelTeacherId fromDictionary:dict];
  73. self.relationType = [self objectOrNilForKey:kVideoCourseModelRelationType fromDictionary:dict];
  74. self.userName = [self objectOrNilForKey:kVideoCourseModelUserName fromDictionary:dict];
  75. self.virtualNumber = [[self objectOrNilForKey:kVideoCourseModelVirtualNumber fromDictionary:dict] doubleValue];
  76. }
  77. return self;
  78. }
  79. - (NSDictionary *)dictionaryRepresentation
  80. {
  81. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  82. [mutableDict setValue:self.internalBaseClassIdentifier forKey:kVideoCourseModelId];
  83. [mutableDict setValue:self.lessonCoverUrl forKey:kVideoCourseModelLessonCoverUrl];
  84. [mutableDict setValue:self.realName forKey:kVideoCourseModelRealName];
  85. [mutableDict setValue:[NSNumber numberWithDouble:self.lessonCount] forKey:kVideoCourseModelLessonCount];
  86. [mutableDict setValue:[NSNumber numberWithInteger:self.musicNum] forKey:kVideoCourseModelMusicNum];
  87. [mutableDict setValue:self.auditVersion forKey:kVideoCourseModelAuditVersion];
  88. [mutableDict setValue:self.lessonSubjectName forKey:kVideoCourseModelLessonSubjectName];
  89. [mutableDict setValue:self.lessonDesc forKey:kVideoCourseModelLessonDesc];
  90. [mutableDict setValue:[NSNumber numberWithDouble:self.lessonPrice] forKey:kVideoCourseModelLessonPrice];
  91. [mutableDict setValue:[NSNumber numberWithDouble:self.countStudent] forKey:kVideoCourseModelCountStudent];
  92. [mutableDict setValue:self.lessonName forKey:kVideoCourseModelLessonName];
  93. [mutableDict setValue:self.avatar forKey:kVideoCourseModelAvatar];
  94. [mutableDict setValue:self.lessonSubject forKey:kVideoCourseModelLessonSubject];
  95. [mutableDict setValue:self.payType forKey:kVideoCourseModelPayType];
  96. [mutableDict setValue:self.teacherId forKey:kVideoCourseModelTeacherId];
  97. [mutableDict setValue:self.relationType forKey:kVideoCourseModelRelationType];
  98. [mutableDict setValue:self.userName forKey:kVideoCourseModelUserName];
  99. [mutableDict setValue:[NSNumber numberWithDouble:self.virtualNumber] forKey:kVideoCourseModelVirtualNumber];
  100. return [NSDictionary dictionaryWithDictionary:mutableDict];
  101. }
  102. - (NSString *)description
  103. {
  104. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  105. }
  106. #pragma mark - Helper Method
  107. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
  108. {
  109. id object = [dict objectForKey:aKey];
  110. if ([object isKindOfClass:[NSNumber class]]) {
  111. NSNumber *number = object;
  112. object = [number stringValue];
  113. }
  114. return [object isEqual:[NSNull null]] ? nil : object;
  115. }
  116. #pragma mark - NSCoding Methods
  117. - (id)initWithCoder:(NSCoder *)aDecoder
  118. {
  119. self = [super init];
  120. self.internalBaseClassIdentifier = [aDecoder decodeObjectForKey:kVideoCourseModelId];
  121. self.lessonCoverUrl = [aDecoder decodeObjectForKey:kVideoCourseModelLessonCoverUrl];
  122. self.realName = [aDecoder decodeObjectForKey:kVideoCourseModelRealName];
  123. self.lessonCount = [aDecoder decodeDoubleForKey:kVideoCourseModelLessonCount];
  124. self.musicNum = [aDecoder decodeIntegerForKey:kVideoCourseModelMusicNum];
  125. self.auditVersion = [aDecoder decodeObjectForKey:kVideoCourseModelAuditVersion];
  126. self.lessonSubjectName = [aDecoder decodeObjectForKey:kVideoCourseModelLessonSubjectName];
  127. self.lessonDesc = [aDecoder decodeObjectForKey:kVideoCourseModelLessonDesc];
  128. self.lessonPrice = [aDecoder decodeDoubleForKey:kVideoCourseModelLessonPrice];
  129. self.countStudent = [aDecoder decodeDoubleForKey:kVideoCourseModelCountStudent];
  130. self.lessonName = [aDecoder decodeObjectForKey:kVideoCourseModelLessonName];
  131. self.avatar = [aDecoder decodeObjectForKey:kVideoCourseModelAvatar];
  132. self.lessonSubject = [aDecoder decodeObjectForKey:kVideoCourseModelLessonSubject];
  133. self.payType = [aDecoder decodeObjectForKey:kVideoCourseModelPayType];
  134. self.teacherId = [aDecoder decodeObjectForKey:kVideoCourseModelTeacherId];
  135. self.relationType = [aDecoder decodeObjectForKey:kVideoCourseModelRelationType];
  136. self.userName = [aDecoder decodeObjectForKey:kVideoCourseModelUserName];
  137. self.virtualNumber = [aDecoder decodeDoubleForKey:kVideoCourseModelVirtualNumber];
  138. return self;
  139. }
  140. - (void)encodeWithCoder:(NSCoder *)aCoder
  141. {
  142. [aCoder encodeObject:_internalBaseClassIdentifier forKey:kVideoCourseModelId];
  143. [aCoder encodeObject:_lessonCoverUrl forKey:kVideoCourseModelLessonCoverUrl];
  144. [aCoder encodeObject:_realName forKey:kVideoCourseModelRealName];
  145. [aCoder encodeDouble:_lessonCount forKey:kVideoCourseModelLessonCount];
  146. [aCoder encodeInteger:_musicNum forKey:kVideoCourseModelMusicNum];
  147. [aCoder encodeObject:_auditVersion forKey:kVideoCourseModelAuditVersion];
  148. [aCoder encodeObject:_lessonSubjectName forKey:kVideoCourseModelLessonSubjectName];
  149. [aCoder encodeObject:_lessonDesc forKey:kVideoCourseModelLessonDesc];
  150. [aCoder encodeDouble:_lessonPrice forKey:kVideoCourseModelLessonPrice];
  151. [aCoder encodeDouble:_countStudent forKey:kVideoCourseModelCountStudent];
  152. [aCoder encodeObject:_lessonName forKey:kVideoCourseModelLessonName];
  153. [aCoder encodeObject:_avatar forKey:kVideoCourseModelAvatar];
  154. [aCoder encodeObject:_lessonSubject forKey:kVideoCourseModelLessonSubject];
  155. [aCoder encodeObject:_payType forKey:kVideoCourseModelPayType];
  156. [aCoder encodeObject:_teacherId forKey:kVideoCourseModelTeacherId];
  157. [aCoder encodeObject:_relationType forKey:kVideoCourseModelRelationType];
  158. [aCoder encodeObject:_userName forKey:kVideoCourseModelUserName];
  159. [aCoder encodeDouble:_virtualNumber forKey:kVideoCourseModelVirtualNumber];
  160. }
  161. - (id)copyWithZone:(NSZone *)zone
  162. {
  163. VideoCourseModel *copy = [[VideoCourseModel alloc] init];
  164. if (copy) {
  165. copy.internalBaseClassIdentifier = [self.internalBaseClassIdentifier copyWithZone:zone];
  166. copy.lessonCoverUrl = [self.lessonCoverUrl copyWithZone:zone];
  167. copy.realName = [self.realName copyWithZone:zone];
  168. copy.lessonCount = self.lessonCount;
  169. copy.musicNum = self.musicNum;
  170. copy.auditVersion = [self.auditVersion copyWithZone:zone];
  171. copy.lessonSubjectName = [self.lessonSubjectName copyWithZone:zone];
  172. copy.lessonDesc = [self.lessonDesc copyWithZone:zone];
  173. copy.lessonPrice = self.lessonPrice;
  174. copy.countStudent = self.countStudent;
  175. copy.lessonName = [self.lessonName copyWithZone:zone];
  176. copy.avatar = [self.avatar copyWithZone:zone];
  177. copy.lessonSubject = [self.lessonSubject copyWithZone:zone];
  178. copy.payType = [self.payType copyWithZone:zone];
  179. copy.teacherId = [self.teacherId copyWithZone:zone];
  180. copy.relationType = [self.relationType copyWithZone:zone];
  181. copy.userName = [self.userName copyWithZone:zone];
  182. copy.virtualNumber = self.virtualNumber;
  183. }
  184. return copy;
  185. }
  186. @end