create
This commit is contained in:
81
ShenQi/Model/WithdrawRecordDataModel.m
Normal file
81
ShenQi/Model/WithdrawRecordDataModel.m
Normal file
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// WithdrawRecordDataModel.m
|
||||
//
|
||||
// Created by Yao on 2024/11/9
|
||||
// Copyright (c) 2024 zL. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WithdrawRecordDataModel.h"
|
||||
#import "WithdrawRecordData.h"
|
||||
|
||||
NSString *const kWithdrawRecordDataModelData = @"data";
|
||||
NSString *const kWithdrawRecordDataModelCode = @"code";
|
||||
|
||||
@interface WithdrawRecordDataModel ()
|
||||
|
||||
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WithdrawRecordDataModel
|
||||
|
||||
@synthesize data = _data;
|
||||
@synthesize code = _code;
|
||||
|
||||
+ (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.data = [WithdrawRecordData modelObjectWithDictionary:[dict objectForKey:kWithdrawRecordDataModelData]];
|
||||
self.code = [[self objectOrNilForKey:kWithdrawRecordDataModelCode fromDictionary:dict] intValue];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSDictionary *)dictionaryRepresentation {
|
||||
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
|
||||
[mutableDict setValue:[self.data dictionaryRepresentation] forKey:kWithdrawRecordDataModelData];
|
||||
[mutableDict setValue:[NSNumber numberWithInteger:self.code] forKey:kWithdrawRecordDataModelCode];
|
||||
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.data = [aDecoder decodeObjectForKey:kWithdrawRecordDataModelData];
|
||||
self.code = [aDecoder decodeIntegerForKey:kWithdrawRecordDataModelCode];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
||||
[aCoder encodeObject:_data forKey:kWithdrawRecordDataModelData];
|
||||
[aCoder encodeInteger:_code forKey:kWithdrawRecordDataModelCode];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
WithdrawRecordDataModel *copy = [[WithdrawRecordDataModel alloc] init];
|
||||
if (copy) {
|
||||
copy.data = [self.data copyWithZone:zone];
|
||||
copy.code = self.code;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user