123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // CourseStudentVos.m
- //
- // Created by Steven on 2024/11/22
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "CourseStudentVos.h"
- NSString *const kCourseStudentVosAvatar = @"avatar";
- NSString *const kCourseStudentVosUserId = @"userId";
- NSString *const kCourseStudentVosImUserId = @"imUserId";
- NSString *const kCourseStudentVosUserName = @"userName";
- @interface CourseStudentVos ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation CourseStudentVos
- @synthesize avatar = _avatar;
- @synthesize userId = _userId;
- @synthesize imUserId = _imUserId;
- @synthesize userName = _userName;
- + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
- {
- return [[self alloc] initWithDictionary:dict];
- }
- - (instancetype)initWithDictionary:(NSDictionary *)dict
- {
- self = [super init];
-
- // This check serves to make sure that a non-NSDictionary object
- // passed into the model class doesn't break the parsing.
- if(self && [dict isKindOfClass:[NSDictionary class]]) {
- self.avatar = [self objectOrNilForKey:kCourseStudentVosAvatar fromDictionary:dict];
- self.userId = [self objectOrNilForKey:kCourseStudentVosUserId fromDictionary:dict];
- self.imUserId = [self objectOrNilForKey:kCourseStudentVosImUserId fromDictionary:dict];
- self.userName = [self objectOrNilForKey:kCourseStudentVosUserName fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation
- {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.avatar forKey:kCourseStudentVosAvatar];
- [mutableDict setValue:self.userId forKey:kCourseStudentVosUserId];
- [mutableDict setValue:self.imUserId forKey:kCourseStudentVosImUserId];
- [mutableDict setValue:self.userName forKey:kCourseStudentVosUserName];
- return [NSDictionary dictionaryWithDictionary:mutableDict];
- }
- - (NSString *)description
- {
- return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
- }
- #pragma mark - Helper Method
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
- {
- id object = [dict objectForKey:aKey];
- if ([object isKindOfClass:[NSNumber class]]) {
- NSNumber *number = object;
- object = [number stringValue];
- }
- return [object isEqual:[NSNull null]] ? nil : object;
- }
- #pragma mark - NSCoding Methods
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- self = [super init];
- self.avatar = [aDecoder decodeObjectForKey:kCourseStudentVosAvatar];
- self.userId = [aDecoder decodeObjectForKey:kCourseStudentVosUserId];
- self.imUserId = [aDecoder decodeObjectForKey:kCourseStudentVosImUserId];
- self.userName = [aDecoder decodeObjectForKey:kCourseStudentVosUserName];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_avatar forKey:kCourseStudentVosAvatar];
- [aCoder encodeObject:_userId forKey:kCourseStudentVosUserId];
- [aCoder encodeObject:_imUserId forKey:kCourseStudentVosImUserId];
- [aCoder encodeObject:_userName forKey:kCourseStudentVosUserName];
- }
- - (id)copyWithZone:(NSZone *)zone
- {
- CourseStudentVos *copy = [[CourseStudentVos alloc] init];
-
- if (copy) {
- copy.avatar = [self.avatar copyWithZone:zone];
- copy.userId = [self.userId copyWithZone:zone];
- copy.imUserId = [self.imUserId copyWithZone:zone];
- copy.userName = [self.userName copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|