create
This commit is contained in:
94
ShenQi/Model/BankModelData.m
Normal file
94
ShenQi/Model/BankModelData.m
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// BankModelData.m
|
||||
//
|
||||
// Created by Yao on 2024/11/9
|
||||
// Copyright (c) 2024 zL. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BankModelData.h"
|
||||
|
||||
NSString *const kBankModelDataBankCode = @"bankCode";
|
||||
NSString *const kBankModelDataId = @"id";
|
||||
NSString *const kBankModelDataBankName = @"bankName";
|
||||
NSString *const kBankModelDataCountry = @"country";
|
||||
|
||||
@interface BankModelData ()
|
||||
|
||||
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BankModelData
|
||||
|
||||
@synthesize bankCode = _bankCode;
|
||||
@synthesize identifier = _identifier;
|
||||
@synthesize bankName = _bankName;
|
||||
@synthesize country = _country;
|
||||
|
||||
+ (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.bankCode = [self objectOrNilForKey:kBankModelDataBankCode fromDictionary:dict];
|
||||
self.identifier = [[self objectOrNilForKey:kBankModelDataId fromDictionary:dict] intValue];
|
||||
self.bankName = [self objectOrNilForKey:kBankModelDataBankName fromDictionary:dict];
|
||||
self.country = [self objectOrNilForKey:kBankModelDataCountry fromDictionary:dict];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSDictionary *)dictionaryRepresentation {
|
||||
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
|
||||
[mutableDict setValue:self.bankCode forKey:kBankModelDataBankCode];
|
||||
[mutableDict setValue:[NSNumber numberWithInteger:self.identifier] forKey:kBankModelDataId];
|
||||
[mutableDict setValue:self.bankName forKey:kBankModelDataBankName];
|
||||
[mutableDict setValue:self.country forKey:kBankModelDataCountry];
|
||||
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.bankCode = [aDecoder decodeObjectForKey:kBankModelDataBankCode];
|
||||
self.identifier = [aDecoder decodeIntegerForKey:kBankModelDataId];
|
||||
self.bankName = [aDecoder decodeObjectForKey:kBankModelDataBankName];
|
||||
self.country = [aDecoder decodeObjectForKey:kBankModelDataCountry];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
||||
[aCoder encodeObject:_bankCode forKey:kBankModelDataBankCode];
|
||||
[aCoder encodeInteger:_identifier forKey:kBankModelDataId];
|
||||
[aCoder encodeObject:_bankName forKey:kBankModelDataBankName];
|
||||
[aCoder encodeObject:_country forKey:kBankModelDataCountry];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
BankModelData *copy = [[BankModelData alloc] init];
|
||||
if (copy) {
|
||||
copy.bankCode = [self.bankCode copyWithZone:zone];
|
||||
copy.identifier = self.identifier;
|
||||
copy.bankName = [self.bankName copyWithZone:zone];
|
||||
copy.country = [self.country copyWithZone:zone];
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user