| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // MOClickResultData.m
- //
- // Created by SuperCabbage on 2024/5/2
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOClickResultData.h"
- NSString *const kMOClickResultDataResult = @"result";
- NSString *const kMOClickResultDataStatus = @"status";
- NSString *const kMOClickResultDataDiamondSeed = @"diamondSeed";
- NSString *const kMOClickResultDataClickSeed = @"clickSeed";
- NSString *const kMOClickResultDataFullDiamond = @"fullDiamond";
- @interface MOClickResultData ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOClickResultData
- @synthesize result = _result;
- @synthesize status = _status;
- @synthesize diamondSeed = _diamondSeed;
- @synthesize clickSeed = _clickSeed;
- @synthesize fullDiamond = _fullDiamond;
- + (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.result = [[self objectOrNilForKey:kMOClickResultDataResult fromDictionary:dict] doubleValue];
- self.status = [[self objectOrNilForKey:kMOClickResultDataStatus fromDictionary:dict] doubleValue];
- self.diamondSeed = [[self objectOrNilForKey:kMOClickResultDataDiamondSeed fromDictionary:dict] longLongValue];
- self.clickSeed = [[self objectOrNilForKey:kMOClickResultDataClickSeed fromDictionary:dict] longLongValue];
-
- self.fullDiamond = [[self objectOrNilForKey:kMOClickResultDataFullDiamond fromDictionary:dict] boolValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.result] forKey:kMOClickResultDataResult];
- [mutableDict setValue:[NSNumber numberWithDouble:self.status] forKey:kMOClickResultDataStatus];
- [mutableDict setValue:[NSNumber numberWithLongLong:self.diamondSeed] forKey:kMOClickResultDataDiamondSeed];
- [mutableDict setValue:[NSNumber numberWithLongLong:self.clickSeed] forKey:kMOClickResultDataClickSeed];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.fullDiamond] forKey:kMOClickResultDataFullDiamond];
- 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.result = [aDecoder decodeDoubleForKey:kMOClickResultDataResult];
- self.status = [aDecoder decodeDoubleForKey:kMOClickResultDataStatus];
- self.diamondSeed = [aDecoder decodeInt64ForKey:kMOClickResultDataDiamondSeed];
- self.clickSeed = [aDecoder decodeInt64ForKey:kMOClickResultDataClickSeed];
-
- self.fullDiamond = [aDecoder decodeBoolForKey:kMOClickResultDataFullDiamond];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_result forKey:kMOClickResultDataResult];
- [aCoder encodeDouble:_status forKey:kMOClickResultDataStatus];
- [aCoder encodeInt64:_diamondSeed forKey:kMOClickResultDataDiamondSeed];
- [aCoder encodeInt64:_clickSeed forKey:kMOClickResultDataClickSeed];
-
- [aCoder encodeBool:_fullDiamond forKey:kMOClickResultDataFullDiamond];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOClickResultData *copy = [[MOClickResultData alloc] init];
-
-
-
- if (copy) {
- copy.result = self.result;
- copy.status = self.status;
- copy.diamondSeed = self.diamondSeed;
- copy.clickSeed = self.clickSeed;
-
- copy.fullDiamond = self.fullDiamond;
- }
-
- return copy;
- }
- @end
|