StyleVideoModel.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // StyleVideoModel.m
  3. //
  4. // Created by Steven on 2022/4/12
  5. // Copyright (c) 2022 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "StyleVideoModel.h"
  8. NSString *const kStyleVideoModelUserId = @"userId";
  9. NSString *const kStyleVideoModelBrowse = @"browse";
  10. NSString *const kStyleVideoModelId = @"id";
  11. NSString *const kStyleVideoModelUpdateTime = @"updateTime";
  12. NSString *const kStyleVideoModelDescribe = @"describe";
  13. NSString *const kStyleVideoModelVideoUrl = @"videoUrl";
  14. NSString *const kStyleVideoModelCreateTime = @"createTime";
  15. NSString *const kStyleVideoModelAuthStatus = @"authStatus";
  16. NSString *const kStyleVideoModelCover = @"cover";
  17. @interface StyleVideoModel ()
  18. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  19. @end
  20. @implementation StyleVideoModel
  21. @synthesize userId = _userId;
  22. @synthesize browse = _browse;
  23. @synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
  24. @synthesize updateTime = _updateTime;
  25. @synthesize describe = _describe;
  26. @synthesize videoUrl = _videoUrl;
  27. @synthesize createTime = _createTime;
  28. @synthesize authStatus = _authStatus;
  29. @synthesize cover = _cover;
  30. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
  31. {
  32. return [[self alloc] initWithDictionary:dict];
  33. }
  34. - (instancetype)initWithDictionary:(NSDictionary *)dict
  35. {
  36. self = [super init];
  37. // This check serves to make sure that a non-NSDictionary object
  38. // passed into the model class doesn't break the parsing.
  39. if(self && [dict isKindOfClass:[NSDictionary class]]) {
  40. self.userId = [self objectOrNilForKey:kStyleVideoModelUserId fromDictionary:dict];
  41. self.browse = [[self objectOrNilForKey:kStyleVideoModelBrowse fromDictionary:dict] doubleValue];
  42. self.internalBaseClassIdentifier = [self objectOrNilForKey:kStyleVideoModelId fromDictionary:dict];
  43. self.updateTime = [self objectOrNilForKey:kStyleVideoModelUpdateTime fromDictionary:dict];
  44. self.describe = [self objectOrNilForKey:kStyleVideoModelDescribe fromDictionary:dict];
  45. self.videoUrl = [self objectOrNilForKey:kStyleVideoModelVideoUrl fromDictionary:dict];
  46. self.createTime = [self objectOrNilForKey:kStyleVideoModelCreateTime fromDictionary:dict];
  47. self.authStatus = [self objectOrNilForKey:kStyleVideoModelAuthStatus fromDictionary:dict];
  48. self.cover = [self objectOrNilForKey:kStyleVideoModelCover fromDictionary:dict];
  49. }
  50. return self;
  51. }
  52. - (NSDictionary *)dictionaryRepresentation
  53. {
  54. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  55. [mutableDict setValue:self.userId forKey:kStyleVideoModelUserId];
  56. [mutableDict setValue:[NSNumber numberWithDouble:self.browse] forKey:kStyleVideoModelBrowse];
  57. [mutableDict setValue:self.internalBaseClassIdentifier forKey:kStyleVideoModelId];
  58. [mutableDict setValue:self.updateTime forKey:kStyleVideoModelUpdateTime];
  59. [mutableDict setValue:self.describe forKey:kStyleVideoModelDescribe];
  60. [mutableDict setValue:self.videoUrl forKey:kStyleVideoModelVideoUrl];
  61. [mutableDict setValue:self.createTime forKey:kStyleVideoModelCreateTime];
  62. [mutableDict setValue:self.authStatus forKey:kStyleVideoModelAuthStatus];
  63. [mutableDict setValue:self.cover forKey:kStyleVideoModelCover];
  64. return [NSDictionary dictionaryWithDictionary:mutableDict];
  65. }
  66. - (NSString *)description
  67. {
  68. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  69. }
  70. #pragma mark - Helper Method
  71. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
  72. {
  73. id object = [dict objectForKey:aKey];
  74. if ([object isKindOfClass:[NSNumber class]]) {
  75. NSNumber *number = object;
  76. object = [number stringValue];
  77. }
  78. return [object isEqual:[NSNull null]] ? nil : object;
  79. }
  80. #pragma mark - NSCoding Methods
  81. - (id)initWithCoder:(NSCoder *)aDecoder
  82. {
  83. self = [super init];
  84. self.userId = [aDecoder decodeObjectForKey:kStyleVideoModelUserId];
  85. self.browse = [aDecoder decodeDoubleForKey:kStyleVideoModelBrowse];
  86. self.internalBaseClassIdentifier = [aDecoder decodeObjectForKey:kStyleVideoModelId];
  87. self.updateTime = [aDecoder decodeObjectForKey:kStyleVideoModelUpdateTime];
  88. self.describe = [aDecoder decodeObjectForKey:kStyleVideoModelDescribe];
  89. self.videoUrl = [aDecoder decodeObjectForKey:kStyleVideoModelVideoUrl];
  90. self.createTime = [aDecoder decodeObjectForKey:kStyleVideoModelCreateTime];
  91. self.authStatus = [aDecoder decodeObjectForKey:kStyleVideoModelAuthStatus];
  92. self.cover = [aDecoder decodeObjectForKey:kStyleVideoModelCover];
  93. return self;
  94. }
  95. - (void)encodeWithCoder:(NSCoder *)aCoder
  96. {
  97. [aCoder encodeObject:_userId forKey:kStyleVideoModelUserId];
  98. [aCoder encodeDouble:_browse forKey:kStyleVideoModelBrowse];
  99. [aCoder encodeObject:_internalBaseClassIdentifier forKey:kStyleVideoModelId];
  100. [aCoder encodeObject:_updateTime forKey:kStyleVideoModelUpdateTime];
  101. [aCoder encodeObject:_describe forKey:kStyleVideoModelDescribe];
  102. [aCoder encodeObject:_videoUrl forKey:kStyleVideoModelVideoUrl];
  103. [aCoder encodeObject:_createTime forKey:kStyleVideoModelCreateTime];
  104. [aCoder encodeObject:_authStatus forKey:kStyleVideoModelAuthStatus];
  105. [aCoder encodeObject:_cover forKey:kStyleVideoModelCover];
  106. }
  107. - (id)copyWithZone:(NSZone *)zone
  108. {
  109. StyleVideoModel *copy = [[StyleVideoModel alloc] init];
  110. if (copy) {
  111. copy.userId = [self.userId copyWithZone:zone];
  112. copy.browse = self.browse;
  113. copy.internalBaseClassIdentifier = [self.internalBaseClassIdentifier copyWithZone:zone];
  114. copy.updateTime = [self.updateTime copyWithZone:zone];
  115. copy.describe = [self.describe copyWithZone:zone];
  116. copy.videoUrl = [self.videoUrl copyWithZone:zone];
  117. copy.createTime = [self.createTime copyWithZone:zone];
  118. copy.authStatus = [self.createTime copyWithZone:zone];
  119. copy.cover = [self.cover copyWithZone:zone];
  120. }
  121. return copy;
  122. }
  123. @end