123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // RecentCourseModel.m
- //
- // Created by Steven on 2022/5/10
- // Copyright (c) 2022 __MyCompanyName__. All rights reserved.
- //
- #import "RecentCourseModel.h"
- NSString *const kRecentCourseModelStatus = @"status";
- NSString *const kRecentCourseModelCourseGroupId = @"courseGroupId";
- NSString *const kRecentCourseModelRealName = @"realName";
- NSString *const kRecentCourseModelAvatar = @"avatar";
- NSString *const kRecentCourseModelCourseId = @"courseId";
- NSString *const kRecentCourseModelCourseType = @"courseType";
- NSString *const kRecentCourseModelTeacherName = @"teacherName";
- NSString *const kRecentCourseModelCourseStartTime = @"courseStartTime";
- NSString *const kRecentCourseModelTeacherId = @"teacherId";
- NSString *const kRecentCourseModelCourseGroupName = @"courseGroupName";
- NSString *const kRecentCourseModelCourseName = @"courseName";
- @interface RecentCourseModel ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation RecentCourseModel
- @synthesize status = _status;
- @synthesize courseGroupId = _courseGroupId;
- @synthesize realName = _realName;
- @synthesize avatar = _avatar;
- @synthesize courseId = _courseId;
- @synthesize courseType = _courseType;
- @synthesize teacherName = _teacherName;
- @synthesize courseStartTime = _courseStartTime;
- @synthesize teacherId = _teacherId;
- @synthesize courseGroupName = _courseGroupName;
- @synthesize courseName = _courseName;
- + (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.status = [self objectOrNilForKey:kRecentCourseModelStatus fromDictionary:dict];
- self.courseGroupId = [self objectOrNilForKey:kRecentCourseModelCourseGroupId fromDictionary:dict];
- self.realName = [self objectOrNilForKey:kRecentCourseModelRealName fromDictionary:dict];
- self.avatar = [self objectOrNilForKey:kRecentCourseModelAvatar fromDictionary:dict];
- self.courseId = [self objectOrNilForKey:kRecentCourseModelCourseId fromDictionary:dict];
- self.courseType = [self objectOrNilForKey:kRecentCourseModelCourseType fromDictionary:dict];
- self.teacherName = [self objectOrNilForKey:kRecentCourseModelTeacherName fromDictionary:dict];
- self.courseStartTime = [self objectOrNilForKey:kRecentCourseModelCourseStartTime fromDictionary:dict];
- self.teacherId = [self objectOrNilForKey:kRecentCourseModelTeacherId fromDictionary:dict];
- self.courseGroupName = [self objectOrNilForKey:kRecentCourseModelCourseGroupName fromDictionary:dict];
- self.courseName = [self objectOrNilForKey:kRecentCourseModelCourseName fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation
- {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.status forKey:kRecentCourseModelStatus];
- [mutableDict setValue:self.courseGroupId forKey:kRecentCourseModelCourseGroupId];
- [mutableDict setValue:self.realName forKey:kRecentCourseModelRealName];
- [mutableDict setValue:self.avatar forKey:kRecentCourseModelAvatar];
- [mutableDict setValue:self.courseId forKey:kRecentCourseModelCourseId];
- [mutableDict setValue:self.courseType forKey:kRecentCourseModelCourseType];
- [mutableDict setValue:self.teacherName forKey:kRecentCourseModelTeacherName];
- [mutableDict setValue:self.courseStartTime forKey:kRecentCourseModelCourseStartTime];
- [mutableDict setValue:self.teacherId forKey:kRecentCourseModelTeacherId];
- [mutableDict setValue:self.courseGroupName forKey:kRecentCourseModelCourseGroupName];
- [mutableDict setValue:self.courseName forKey:kRecentCourseModelCourseName];
- 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.status = [aDecoder decodeObjectForKey:kRecentCourseModelStatus];
- self.courseGroupId = [aDecoder decodeObjectForKey:kRecentCourseModelCourseGroupId];
- self.realName = [aDecoder decodeObjectForKey:kRecentCourseModelRealName];
- self.avatar = [aDecoder decodeObjectForKey:kRecentCourseModelAvatar];
- self.courseId = [aDecoder decodeObjectForKey:kRecentCourseModelCourseId];
- self.courseType = [aDecoder decodeObjectForKey:kRecentCourseModelCourseType];
- self.teacherName = [aDecoder decodeObjectForKey:kRecentCourseModelTeacherName];
- self.courseStartTime = [aDecoder decodeObjectForKey:kRecentCourseModelCourseStartTime];
- self.teacherId = [aDecoder decodeObjectForKey:kRecentCourseModelTeacherId];
- self.courseGroupName = [aDecoder decodeObjectForKey:kRecentCourseModelCourseGroupName];
- self.courseName = [aDecoder decodeObjectForKey:kRecentCourseModelCourseName];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_status forKey:kRecentCourseModelStatus];
- [aCoder encodeObject:_courseGroupId forKey:kRecentCourseModelCourseGroupId];
- [aCoder encodeObject:_realName forKey:kRecentCourseModelRealName];
- [aCoder encodeObject:_avatar forKey:kRecentCourseModelAvatar];
- [aCoder encodeObject:_courseId forKey:kRecentCourseModelCourseId];
- [aCoder encodeObject:_courseType forKey:kRecentCourseModelCourseType];
- [aCoder encodeObject:_teacherName forKey:kRecentCourseModelTeacherName];
- [aCoder encodeObject:_courseStartTime forKey:kRecentCourseModelCourseStartTime];
- [aCoder encodeObject:_teacherId forKey:kRecentCourseModelTeacherId];
- [aCoder encodeObject:_courseGroupName forKey:kRecentCourseModelCourseGroupName];
- [aCoder encodeObject:_courseName forKey:kRecentCourseModelCourseName];
- }
- - (id)copyWithZone:(NSZone *)zone
- {
- RecentCourseModel *copy = [[RecentCourseModel alloc] init];
-
- if (copy) {
- copy.status = [self.status copyWithZone:zone];
- copy.courseGroupId = [self.courseGroupId copyWithZone:zone];
- copy.realName = [self.realName copyWithZone:zone];
- copy.avatar = [self.avatar copyWithZone:zone];
- copy.courseId = [self.courseId copyWithZone:zone];
- copy.courseType = [self.courseType copyWithZone:zone];
- copy.teacherName = [self.teacherName copyWithZone:zone];
- copy.courseStartTime = [self.courseStartTime copyWithZone:zone];
- copy.teacherId = [self.teacherId copyWithZone:zone];
- copy.courseGroupName = [self.courseGroupName copyWithZone:zone];
- copy.courseName = [self.courseName copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|