| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- //
- // MOGiftlist.m
- //
- // Created by SuperCabbage on 2023/11/24
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOGiftlist.h"
- #import "MOGiftInfo.h"
- #import "MOEffect.h"
- NSString *const kMOGiftlistGiftInfo = @"gift";
- NSString *const kMOGiftlistLock = @"lock";
- NSString *const kMOGiftlistBasicExp = @"basicExp";
- NSString *const kMOGiftlistAdditionExp = @"additionExp";
- NSString *const kMOGiftlistAmount= @"amount";
- NSString *const kMOGiftlistStore= @"store";
- NSString *const kMOGiftlistId= @"id";
- NSString *const kMOGiftlistNewUnlock = @"newUnlock";
- NSString *const kMOGiftlistNewGet = @"newGet";
- NSString *const kMOGiftlistExpireTime = @"expireTime";
- NSString *const kMOGiftlistNameingAvatar = @"nameingAvatar";
- @interface MOGiftlist ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOGiftlist
- @synthesize giftInfo = _giftInfo;
- @synthesize lock = _lock;
- @synthesize basicExp = _basicExp;
- @synthesize additionExp = _additionExp;
- @synthesize amount = _amount;
- @synthesize store = _store;
- @synthesize id = _id;
- @synthesize newUnlock = _newUnlock;
- @synthesize newGet = _newGet;
- @synthesize expireTime = _expireTime;
- @synthesize nameingAvatar = _nameingAvatar;
- + (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.giftInfo = [MOGiftInfo modelObjectWithDictionary:[dict objectForKey:kMOGiftlistGiftInfo]];
- self.effect = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftlistGiftInfo]];
- self.lock = [[self objectOrNilForKey:kMOGiftlistLock fromDictionary:dict] boolValue];
-
- self.basicExp = [[self objectOrNilForKey:kMOGiftlistBasicExp fromDictionary:dict] doubleValue];
- self.additionExp = [[self objectOrNilForKey:kMOGiftlistAdditionExp fromDictionary:dict] doubleValue];
- self.amount = [[self objectOrNilForKey:kMOGiftlistAmount fromDictionary:dict] doubleValue];
-
- //背包
- self.store = [MOEffect modelObjectWithDictionary:[dict objectForKey:kMOGiftlistStore]];
- self.id = [self objectOrNilForKey:kMOGiftlistId fromDictionary:dict];
-
- self.newUnlock = [[self objectOrNilForKey:kMOGiftlistNewUnlock fromDictionary:dict] boolValue];
- self.newGet = [[self objectOrNilForKey:kMOGiftlistNewGet fromDictionary:dict] boolValue];
- self.expireTime = [[self objectOrNilForKey:kMOGiftlistExpireTime fromDictionary:dict] doubleValue];
- self.nameingAvatar = [self objectOrNilForKey:kMOGiftlistNameingAvatar fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[self.giftInfo dictionaryRepresentation] forKey:kMOGiftlistGiftInfo];
- [mutableDict setValue:[self.effect dictionaryRepresentation] forKey:kMOGiftlistGiftInfo];
- [mutableDict setValue:[NSNumber numberWithBool:self.lock] forKey:kMOGiftlistLock];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.basicExp] forKey:kMOGiftlistBasicExp];
- [mutableDict setValue:[NSNumber numberWithDouble:self.additionExp] forKey:kMOGiftlistAdditionExp];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOGiftlistAmount];
-
- [mutableDict setValue:[self.store dictionaryRepresentation] forKey:kMOGiftlistStore];
- [mutableDict setValue:self.id forKey:kMOGiftlistId];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.newUnlock] forKey:kMOGiftlistNewUnlock];
- [mutableDict setValue:[NSNumber numberWithBool:self.newGet] forKey:kMOGiftlistNewGet];
- [mutableDict setValue:[NSNumber numberWithDouble:self.expireTime] forKey:kMOGiftlistExpireTime];
- [mutableDict setValue:self.nameingAvatar forKey:kMOGiftlistNameingAvatar];
- 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.giftInfo = [aDecoder decodeObjectForKey:kMOGiftlistGiftInfo];
- self.effect = [aDecoder decodeObjectForKey:kMOGiftlistGiftInfo];
- self.lock = [aDecoder decodeBoolForKey:kMOGiftlistLock];
-
- self.basicExp = [aDecoder decodeDoubleForKey:kMOGiftlistBasicExp];
- self.additionExp = [aDecoder decodeDoubleForKey:kMOGiftlistAdditionExp];
-
- self.amount = [aDecoder decodeDoubleForKey:kMOGiftlistAmount];
-
- self.store = [aDecoder decodeObjectForKey:kMOGiftlistStore];
- self.id = [aDecoder decodeObjectForKey:kMOGiftlistId];
-
- self.newUnlock = [aDecoder decodeBoolForKey:kMOGiftlistNewUnlock];
- self.newGet = [aDecoder decodeBoolForKey:kMOGiftlistNewGet];
- self.expireTime = [aDecoder decodeDoubleForKey:kMOGiftlistExpireTime];
- self.nameingAvatar = [aDecoder decodeObjectForKey:kMOGiftlistNameingAvatar];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_giftInfo forKey:kMOGiftlistGiftInfo];
- [aCoder encodeObject:_effect forKey:kMOGiftlistGiftInfo];
- [aCoder encodeBool:_lock forKey:kMOGiftlistLock];
-
- [aCoder encodeDouble:_basicExp forKey:kMOGiftlistBasicExp];
- [aCoder encodeDouble:_additionExp forKey:kMOGiftlistAdditionExp];
-
- [aCoder encodeDouble:_amount forKey:kMOGiftlistAmount];
-
- [aCoder encodeObject:_store forKey:kMOGiftlistStore];
- [aCoder encodeObject:_id forKey:kMOGiftlistId];
-
- [aCoder encodeBool:_newUnlock forKey:kMOGiftlistNewUnlock];
- [aCoder encodeBool:_newGet forKey:kMOGiftlistNewGet];
- [aCoder encodeDouble:_expireTime forKey:kMOGiftlistExpireTime];
-
- [aCoder encodeObject:_nameingAvatar forKey:kMOGiftlistNameingAvatar];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOGiftlist *copy = [[MOGiftlist alloc] init];
- if (copy) {
- copy.giftInfo = [self.giftInfo copyWithZone:zone];
- copy.effect = [self.effect copyWithZone:zone];
- copy.lock = self.lock;
-
- copy.basicExp = self.basicExp;
- copy.additionExp = self.additionExp;
-
- copy.amount = self.amount;
- copy.tempNum = self.tempNum;
- copy.isBag = self.isBag;
- copy.endGiftNum = self.endGiftNum;
- copy.tempNum = self.tempNum;
-
- copy.store = [self.store copyWithZone:zone];
- copy.id = [self.id copyWithZone:zone];
-
- copy.newUnlock = self.newUnlock;
- copy.newGet = self.newGet;
- copy.expireTime = self.expireTime;
-
- copy.nameingAvatar = [self.nameingAvatar copyWithZone:zone];
- }
-
- return copy;
- }
- - (BOOL)isEqual:(id)object {
- if (self == object) return YES;
- if (![object isKindOfClass:[self class]]) return NO;
-
- MOGiftlist *other = (MOGiftlist *)object;
- return self.id == other.id
- && self.lock == other.lock
- && [self.nameingAvatar isEqualToString:other.nameingAvatar]
- && self.newUnlock == other.newUnlock
- && self.newGet == other.newGet
- && self.expireTime == other.expireTime
- && self.isBag == other.isBag
- && self.amount == other.amount;
- }
- @end
|