CourseStudentVos.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // CourseStudentVos.m
  3. //
  4. // Created by Steven on 2024/11/22
  5. // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "CourseStudentVos.h"
  8. NSString *const kCourseStudentVosAvatar = @"avatar";
  9. NSString *const kCourseStudentVosUserId = @"userId";
  10. NSString *const kCourseStudentVosImUserId = @"imUserId";
  11. NSString *const kCourseStudentVosUserName = @"userName";
  12. @interface CourseStudentVos ()
  13. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  14. @end
  15. @implementation CourseStudentVos
  16. @synthesize avatar = _avatar;
  17. @synthesize userId = _userId;
  18. @synthesize imUserId = _imUserId;
  19. @synthesize userName = _userName;
  20. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
  21. {
  22. return [[self alloc] initWithDictionary:dict];
  23. }
  24. - (instancetype)initWithDictionary:(NSDictionary *)dict
  25. {
  26. self = [super init];
  27. // This check serves to make sure that a non-NSDictionary object
  28. // passed into the model class doesn't break the parsing.
  29. if(self && [dict isKindOfClass:[NSDictionary class]]) {
  30. self.avatar = [self objectOrNilForKey:kCourseStudentVosAvatar fromDictionary:dict];
  31. self.userId = [self objectOrNilForKey:kCourseStudentVosUserId fromDictionary:dict];
  32. self.imUserId = [self objectOrNilForKey:kCourseStudentVosImUserId fromDictionary:dict];
  33. self.userName = [self objectOrNilForKey:kCourseStudentVosUserName fromDictionary:dict];
  34. }
  35. return self;
  36. }
  37. - (NSDictionary *)dictionaryRepresentation
  38. {
  39. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  40. [mutableDict setValue:self.avatar forKey:kCourseStudentVosAvatar];
  41. [mutableDict setValue:self.userId forKey:kCourseStudentVosUserId];
  42. [mutableDict setValue:self.imUserId forKey:kCourseStudentVosImUserId];
  43. [mutableDict setValue:self.userName forKey:kCourseStudentVosUserName];
  44. return [NSDictionary dictionaryWithDictionary:mutableDict];
  45. }
  46. - (NSString *)description
  47. {
  48. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  49. }
  50. #pragma mark - Helper Method
  51. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
  52. {
  53. id object = [dict objectForKey:aKey];
  54. if ([object isKindOfClass:[NSNumber class]]) {
  55. NSNumber *number = object;
  56. object = [number stringValue];
  57. }
  58. return [object isEqual:[NSNull null]] ? nil : object;
  59. }
  60. #pragma mark - NSCoding Methods
  61. - (id)initWithCoder:(NSCoder *)aDecoder
  62. {
  63. self = [super init];
  64. self.avatar = [aDecoder decodeObjectForKey:kCourseStudentVosAvatar];
  65. self.userId = [aDecoder decodeObjectForKey:kCourseStudentVosUserId];
  66. self.imUserId = [aDecoder decodeObjectForKey:kCourseStudentVosImUserId];
  67. self.userName = [aDecoder decodeObjectForKey:kCourseStudentVosUserName];
  68. return self;
  69. }
  70. - (void)encodeWithCoder:(NSCoder *)aCoder
  71. {
  72. [aCoder encodeObject:_avatar forKey:kCourseStudentVosAvatar];
  73. [aCoder encodeObject:_userId forKey:kCourseStudentVosUserId];
  74. [aCoder encodeObject:_imUserId forKey:kCourseStudentVosImUserId];
  75. [aCoder encodeObject:_userName forKey:kCourseStudentVosUserName];
  76. }
  77. - (id)copyWithZone:(NSZone *)zone
  78. {
  79. CourseStudentVos *copy = [[CourseStudentVos alloc] init];
  80. if (copy) {
  81. copy.avatar = [self.avatar copyWithZone:zone];
  82. copy.userId = [self.userId copyWithZone:zone];
  83. copy.imUserId = [self.imUserId copyWithZone:zone];
  84. copy.userName = [self.userName copyWithZone:zone];
  85. }
  86. return copy;
  87. }
  88. @end