| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // MOEventList.m
- //
- // Created by SuperCabbage on 2024/1/31
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOEventList.h"
- #import "MOMedalList.h"
- NSString *const kMOEventListType = @"type";
- NSString *const kMOEventListMedalList = @"medal";
- NSString *const kMOEventListLevel = @"level";
- @interface MOEventList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOEventList
- @synthesize type = _type;
- @synthesize medalList = _medalList;
- @synthesize level = _level;
- + (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.type = [[self objectOrNilForKey:kMOEventListType fromDictionary:dict] doubleValue];
- self.medalList = [MOMedalList modelObjectWithDictionary:[dict objectForKey:kMOEventListMedalList]];
- self.level = [[self objectOrNilForKey:kMOEventListLevel fromDictionary:dict] doubleValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMOEventListType];
- [mutableDict setValue:[self.medalList dictionaryRepresentation] forKey:kMOEventListMedalList];
- [mutableDict setValue:[NSNumber numberWithDouble:self.level] forKey:kMOEventListLevel];
- 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];
- return [object isEqual:[NSNull null]] ? nil : object;
- }
- #pragma mark - NSCoding Methods
- - (id)initWithCoder:(NSCoder *)aDecoder {
- self = [super init];
- self.type = [aDecoder decodeDoubleForKey:kMOEventListType];
- self.medalList = [aDecoder decodeObjectForKey:kMOEventListMedalList];
- self.level = [aDecoder decodeDoubleForKey:kMOEventListLevel];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_type forKey:kMOEventListType];
- [aCoder encodeObject:_medalList forKey:kMOEventListMedalList];
- [aCoder encodeDouble:_level forKey:kMOEventListLevel];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOEventList *copy = [[MOEventList alloc] init];
-
-
-
- if (copy) {
- copy.type = self.type;
- copy.medalList = [self.medalList copyWithZone:zone];
- copy.level = self.level;
- }
-
- return copy;
- }
- @end
|