| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- //
- // MORedSendConfigs.m
- //
- // Created by SuperCabbage on 2024/6/14
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MORedSendConfigs.h"
- NSString *const kMORedSendConfigsMaxNum = @"maxNum";
- NSString *const kMORedSendConfigsMinNum = @"minNum";
- NSString *const kMORedSendConfigsCode = @"code";
- NSString *const kMORedSendConfigsScope = @"scope";
- NSString *const kMORedSendConfigsMaxAmount = @"maxAmount";
- NSString *const kMORedSendConfigsMinAmount = @"minAmount";
- NSString *const kMORedSendConfigsType = @"type";
- NSString *const kMORedSendConfigsOptionalNum = @"optionalNum";
- @interface MORedSendConfigs ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MORedSendConfigs
- @synthesize maxNum = _maxNum;
- @synthesize minNum = _minNum;
- @synthesize code = _code;
- @synthesize scope = _scope;
- @synthesize maxAmount = _maxAmount;
- @synthesize minAmount = _minAmount;
- @synthesize type = _type;
- @synthesize optionalNum = _optionalNum;
- + (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.maxNum = [[self objectOrNilForKey:kMORedSendConfigsMaxNum fromDictionary:dict] doubleValue];
- self.minNum = [[self objectOrNilForKey:kMORedSendConfigsMinNum fromDictionary:dict] doubleValue];
- self.code = [[self objectOrNilForKey:kMORedSendConfigsCode fromDictionary:dict] doubleValue];
- self.scope = [[self objectOrNilForKey:kMORedSendConfigsScope fromDictionary:dict] doubleValue];
- self.maxAmount = [[self objectOrNilForKey:kMORedSendConfigsMaxAmount fromDictionary:dict] doubleValue];
- self.minAmount = [[self objectOrNilForKey:kMORedSendConfigsMinAmount fromDictionary:dict] doubleValue];
- self.type = [[self objectOrNilForKey:kMORedSendConfigsType fromDictionary:dict] doubleValue];
- self.optionalNum = [self objectOrNilForKey:kMORedSendConfigsOptionalNum fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.maxNum] forKey:kMORedSendConfigsMaxNum];
- [mutableDict setValue:[NSNumber numberWithDouble:self.minNum] forKey:kMORedSendConfigsMinNum];
- [mutableDict setValue:[NSNumber numberWithDouble:self.code] forKey:kMORedSendConfigsCode];
- [mutableDict setValue:[NSNumber numberWithDouble:self.scope] forKey:kMORedSendConfigsScope];
- [mutableDict setValue:[NSNumber numberWithDouble:self.maxAmount] forKey:kMORedSendConfigsMaxAmount];
- [mutableDict setValue:[NSNumber numberWithDouble:self.minAmount] forKey:kMORedSendConfigsMinAmount];
- [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMORedSendConfigsType];
-
- NSMutableArray *tempArrayForOptionalNum = [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.optionalNum) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForOptionalNum addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForOptionalNum addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForOptionalNum] forKey:kMORedSendConfigsOptionalNum];
-
- 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.maxNum = [aDecoder decodeDoubleForKey:kMORedSendConfigsMaxNum];
- self.minNum = [aDecoder decodeDoubleForKey:kMORedSendConfigsMinNum];
- self.code = [aDecoder decodeDoubleForKey:kMORedSendConfigsCode];
- self.scope = [aDecoder decodeDoubleForKey:kMORedSendConfigsScope];
- self.maxAmount = [aDecoder decodeDoubleForKey:kMORedSendConfigsMaxAmount];
- self.minAmount = [aDecoder decodeDoubleForKey:kMORedSendConfigsMinAmount];
- self.type = [aDecoder decodeDoubleForKey:kMORedSendConfigsType];
- self.optionalNum = [aDecoder decodeObjectForKey:kMORedSendConfigsOptionalNum];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_maxNum forKey:kMORedSendConfigsMaxNum];
- [aCoder encodeDouble:_minNum forKey:kMORedSendConfigsMinNum];
- [aCoder encodeDouble:_code forKey:kMORedSendConfigsCode];
- [aCoder encodeDouble:_scope forKey:kMORedSendConfigsScope];
- [aCoder encodeDouble:_maxAmount forKey:kMORedSendConfigsMaxAmount];
- [aCoder encodeDouble:_minAmount forKey:kMORedSendConfigsMinAmount];
- [aCoder encodeDouble:_type forKey:kMORedSendConfigsType];
- [aCoder encodeObject:_optionalNum forKey:kMORedSendConfigsOptionalNum];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MORedSendConfigs *copy = [[MORedSendConfigs alloc] init];
-
-
-
- if (copy) {
- copy.maxNum = self.maxNum;
- copy.minNum = self.minNum;
- copy.code = self.code;
- copy.scope = self.scope;
- copy.maxAmount = self.maxAmount;
- copy.minAmount = self.minAmount;
- copy.type = self.type;
- copy.isSelect = copy.isSelect;
- copy.optionalNum = [self.optionalNum copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|