MaterialList.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MaterialList.m
  3. //
  4. // Created by Steven on 2023/5/14
  5. // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MaterialList.h"
  8. NSString *const kMaterialListAdviseStudyTimeSecond = @"adviseStudyTimeSecond";
  9. NSString *const kMaterialListContent = @"content";
  10. NSString *const kMaterialListKnowledgePointId = @"knowledgePointId";
  11. NSString *const kMaterialListUpdateTime = @"updateTime";
  12. NSString *const kMaterialListId = @"id";
  13. NSString *const kMaterialListCourseTypeCode = @"courseTypeCode";
  14. NSString *const kMaterialListSn = @"sn";
  15. NSString *const kMaterialListType = @"type";
  16. NSString *const kMaterialListName = @"name";
  17. NSString *const kMaterialListKnowledgePointMaterialRelationId = @"knowledgePointMaterialRelationId";
  18. @interface MaterialList ()
  19. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  20. @end
  21. @implementation MaterialList
  22. @synthesize adviseStudyTimeSecond = _adviseStudyTimeSecond;
  23. @synthesize content = _content;
  24. @synthesize knowledgePointId = _knowledgePointId;
  25. @synthesize updateTime = _updateTime;
  26. @synthesize materialListIdentifier = _materialListIdentifier;
  27. @synthesize courseTypeCode = _courseTypeCode;
  28. @synthesize sn = _sn;
  29. @synthesize type = _type;
  30. @synthesize name = _name;
  31. @synthesize knowledgePointMaterialRelationId = _knowledgePointMaterialRelationId;
  32. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
  33. {
  34. return [[self alloc] initWithDictionary:dict];
  35. }
  36. - (instancetype)initWithDictionary:(NSDictionary *)dict
  37. {
  38. self = [super init];
  39. // This check serves to make sure that a non-NSDictionary object
  40. // passed into the model class doesn't break the parsing.
  41. if(self && [dict isKindOfClass:[NSDictionary class]]) {
  42. self.adviseStudyTimeSecond = [self objectOrNilForKey:kMaterialListAdviseStudyTimeSecond fromDictionary:dict];
  43. self.content = [self objectOrNilForKey:kMaterialListContent fromDictionary:dict];
  44. self.knowledgePointId = [self objectOrNilForKey:kMaterialListKnowledgePointId fromDictionary:dict];
  45. self.updateTime = [self objectOrNilForKey:kMaterialListUpdateTime fromDictionary:dict];
  46. self.materialListIdentifier = [self objectOrNilForKey:kMaterialListId fromDictionary:dict];
  47. self.courseTypeCode = [self objectOrNilForKey:kMaterialListCourseTypeCode fromDictionary:dict];
  48. self.sn = [self objectOrNilForKey:kMaterialListSn fromDictionary:dict];
  49. self.type = [self objectOrNilForKey:kMaterialListType fromDictionary:dict];
  50. self.name = [self objectOrNilForKey:kMaterialListName fromDictionary:dict];
  51. self.knowledgePointMaterialRelationId = [self objectOrNilForKey:kMaterialListKnowledgePointMaterialRelationId fromDictionary:dict];
  52. }
  53. return self;
  54. }
  55. - (NSDictionary *)dictionaryRepresentation
  56. {
  57. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  58. [mutableDict setValue:self.adviseStudyTimeSecond forKey:kMaterialListAdviseStudyTimeSecond];
  59. [mutableDict setValue:self.content forKey:kMaterialListContent];
  60. [mutableDict setValue:self.knowledgePointId forKey:kMaterialListKnowledgePointId];
  61. [mutableDict setValue:self.updateTime forKey:kMaterialListUpdateTime];
  62. [mutableDict setValue:self.materialListIdentifier forKey:kMaterialListId];
  63. [mutableDict setValue:self.courseTypeCode forKey:kMaterialListCourseTypeCode];
  64. [mutableDict setValue:self.sn forKey:kMaterialListSn];
  65. [mutableDict setValue:self.type forKey:kMaterialListType];
  66. [mutableDict setValue:self.name forKey:kMaterialListName];
  67. [mutableDict setValue:self.knowledgePointMaterialRelationId forKey:kMaterialListKnowledgePointMaterialRelationId];
  68. return [NSDictionary dictionaryWithDictionary:mutableDict];
  69. }
  70. - (NSString *)description
  71. {
  72. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  73. }
  74. #pragma mark - Helper Method
  75. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
  76. {
  77. id object = [dict objectForKey:aKey];
  78. if ([object isKindOfClass:[NSNumber class]]) {
  79. NSNumber *number = object;
  80. object = [number stringValue];
  81. }
  82. return [object isEqual:[NSNull null]] ? nil : object;
  83. }
  84. #pragma mark - NSCoding Methods
  85. - (id)initWithCoder:(NSCoder *)aDecoder
  86. {
  87. self = [super init];
  88. self.adviseStudyTimeSecond = [aDecoder decodeObjectForKey:kMaterialListAdviseStudyTimeSecond];
  89. self.content = [aDecoder decodeObjectForKey:kMaterialListContent];
  90. self.knowledgePointId = [aDecoder decodeObjectForKey:kMaterialListKnowledgePointId];
  91. self.updateTime = [aDecoder decodeObjectForKey:kMaterialListUpdateTime];
  92. self.materialListIdentifier = [aDecoder decodeObjectForKey:kMaterialListId];
  93. self.courseTypeCode = [aDecoder decodeObjectForKey:kMaterialListCourseTypeCode];
  94. self.sn = [aDecoder decodeObjectForKey:kMaterialListSn];
  95. self.type = [aDecoder decodeObjectForKey:kMaterialListType];
  96. self.name = [aDecoder decodeObjectForKey:kMaterialListName];
  97. self.knowledgePointMaterialRelationId = [aDecoder decodeObjectForKey:kMaterialListKnowledgePointMaterialRelationId];
  98. return self;
  99. }
  100. - (void)encodeWithCoder:(NSCoder *)aCoder
  101. {
  102. [aCoder encodeObject:_adviseStudyTimeSecond forKey:kMaterialListAdviseStudyTimeSecond];
  103. [aCoder encodeObject:_content forKey:kMaterialListContent];
  104. [aCoder encodeObject:_knowledgePointId forKey:kMaterialListKnowledgePointId];
  105. [aCoder encodeObject:_updateTime forKey:kMaterialListUpdateTime];
  106. [aCoder encodeObject:_materialListIdentifier forKey:kMaterialListId];
  107. [aCoder encodeObject:_courseTypeCode forKey:kMaterialListCourseTypeCode];
  108. [aCoder encodeObject:_sn forKey:kMaterialListSn];
  109. [aCoder encodeObject:_type forKey:kMaterialListType];
  110. [aCoder encodeObject:_name forKey:kMaterialListName];
  111. [aCoder encodeObject:_knowledgePointMaterialRelationId forKey:kMaterialListKnowledgePointMaterialRelationId];
  112. }
  113. - (id)copyWithZone:(NSZone *)zone
  114. {
  115. MaterialList *copy = [[MaterialList alloc] init];
  116. if (copy) {
  117. copy.adviseStudyTimeSecond = [self.adviseStudyTimeSecond copyWithZone:zone];
  118. copy.content = [self.content copyWithZone:zone];
  119. copy.knowledgePointId = [self.knowledgePointId copyWithZone:zone];
  120. copy.updateTime = [self.updateTime copyWithZone:zone];
  121. copy.materialListIdentifier = [self.materialListIdentifier copyWithZone:zone];
  122. copy.courseTypeCode = [self.courseTypeCode copyWithZone:zone];
  123. copy.sn = [self.sn copyWithZone:zone];
  124. copy.type = [self.type copyWithZone:zone];
  125. copy.name = [self.name copyWithZone:zone];
  126. copy.knowledgePointMaterialRelationId = [self.knowledgePointMaterialRelationId copyWithZone:zone];
  127. }
  128. return copy;
  129. }
  130. @end