| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // MOReceivingBaseData.m
- //
- // Created by SuperCabbage on 2024/6/19
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOReceivingBaseData.h"
- #import "MOReceivingInfo.h"
- NSString *const kMOReceivingBaseDataReceivedAmount = @"receivedAmount";
- NSString *const kMOReceivingBaseDataNext = @"next";
- NSString *const kMOReceivingBaseDataWalletDiamonds = @"walletDiamonds";
- NSString *const kMOReceivingBaseDataReceivingInfo = @"receivingInfo";
- NSString *const kMOReceivingBaseDataFirstTime = @"firstTime";
- NSString *const kMOReceivingBaseDataLastReceivedNum = @"lastReceivedNum";
- @interface MOReceivingBaseData ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOReceivingBaseData
- @synthesize receivedAmount = _receivedAmount;
- @synthesize next = _next;
- @synthesize walletDiamonds = _walletDiamonds;
- @synthesize receivingInfo = _receivingInfo;
- @synthesize firstTime = _firstTime;
- @synthesize lastReceivedNum = _lastReceivedNum;
- + (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.receivedAmount = [[self objectOrNilForKey:kMOReceivingBaseDataReceivedAmount fromDictionary:dict] doubleValue];
- self.next = [self objectOrNilForKey:kMOReceivingBaseDataNext fromDictionary:dict];
- self.walletDiamonds = [[self objectOrNilForKey:kMOReceivingBaseDataWalletDiamonds fromDictionary:dict] doubleValue];
- self.receivingInfo = [MOReceivingInfo modelObjectWithDictionary:[dict objectForKey:kMOReceivingBaseDataReceivingInfo]];
- self.firstTime = [[self objectOrNilForKey:kMOReceivingBaseDataFirstTime fromDictionary:dict] boolValue];
-
- self.lastReceivedNum = [[self objectOrNilForKey:kMOReceivingBaseDataLastReceivedNum fromDictionary:dict] doubleValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.receivedAmount] forKey:kMOReceivingBaseDataReceivedAmount];
- [mutableDict setValue:self.next forKey:kMOReceivingBaseDataNext];
- [mutableDict setValue:[NSNumber numberWithDouble:self.walletDiamonds] forKey:kMOReceivingBaseDataWalletDiamonds];
- [mutableDict setValue:[self.receivingInfo dictionaryRepresentation] forKey:kMOReceivingBaseDataReceivingInfo];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.firstTime] forKey:kMOReceivingBaseDataFirstTime];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.lastReceivedNum] forKey:kMOReceivingBaseDataLastReceivedNum];
- 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.receivedAmount = [aDecoder decodeDoubleForKey:kMOReceivingBaseDataReceivedAmount];
- self.next = [aDecoder decodeObjectForKey:kMOReceivingBaseDataNext];
- self.walletDiamonds = [aDecoder decodeDoubleForKey:kMOReceivingBaseDataWalletDiamonds];
- self.receivingInfo = [aDecoder decodeObjectForKey:kMOReceivingBaseDataReceivingInfo];
-
- self.firstTime = [aDecoder decodeBoolForKey:kMOReceivingBaseDataFirstTime];
-
- self.lastReceivedNum = [aDecoder decodeDoubleForKey:kMOReceivingBaseDataLastReceivedNum];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_receivedAmount forKey:kMOReceivingBaseDataReceivedAmount];
- [aCoder encodeObject:_next forKey:kMOReceivingBaseDataNext];
- [aCoder encodeDouble:_walletDiamonds forKey:kMOReceivingBaseDataWalletDiamonds];
- [aCoder encodeObject:_receivingInfo forKey:kMOReceivingBaseDataReceivingInfo];
-
- [aCoder encodeBool:_firstTime forKey:kMOReceivingBaseDataFirstTime];
-
- [aCoder encodeDouble:_lastReceivedNum forKey:kMOReceivingBaseDataLastReceivedNum];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOReceivingBaseData *copy = [[MOReceivingBaseData alloc] init];
-
-
-
- if (copy) {
- copy.receivedAmount = self.receivedAmount;
- copy.next = [self.next copyWithZone:zone];
- copy.walletDiamonds = self.walletDiamonds;
- copy.receivingInfo = [self.receivingInfo copyWithZone:zone];
-
- copy.firstTime = self.firstTime;
-
- copy.lastReceivedNum = self.lastReceivedNum;
- }
-
- return copy;
- }
- @end
|