| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- //
- // MOSecurityData.m
- //
- // Created by SuperCabbage on 2025/3/12
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MOSecurityData.h"
- #import "MOMobileInfo.h"
- NSString *const kMOSecurityDataEmail = @"email";
- NSString *const kMOSecurityDataPaymentPwd = @"paymentPwd";
- NSString *const kMOSecurityDataLoginPwd = @"loginPwd";
- NSString *const kMOSecurityDataLevel = @"level";
- NSString *const kMOSecurityDataMobileInfo = @"mobile";
- NSString *const kMOSecurityDataAllowChangeMobile= @"allowChangeMobile";
- NSString *const kMOSecurityDataAllowChangeEmail = @"allowChangeEmail";
- @interface MOSecurityData ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOSecurityData
- @synthesize email = _email;
- @synthesize paymentPwd = _paymentPwd;
- @synthesize loginPwd = _loginPwd;
- @synthesize level = _level;
- @synthesize mobileInfo = _mobileInfo;
- @synthesize allowChangeMobile = _allowChangeMobile;
- @synthesize allowChangeEmail = _allowChangeEmail;
- + (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.email = [self objectOrNilForKey:kMOSecurityDataEmail fromDictionary:dict];
- self.paymentPwd = [[self objectOrNilForKey:kMOSecurityDataPaymentPwd fromDictionary:dict] boolValue];
- self.loginPwd = [[self objectOrNilForKey:kMOSecurityDataLoginPwd fromDictionary:dict] boolValue];
- self.level = [[self objectOrNilForKey:kMOSecurityDataLevel fromDictionary:dict] doubleValue];
- self.mobileInfo = [MOMobileInfo modelObjectWithDictionary:[dict objectForKey:kMOSecurityDataMobileInfo]];
- self.allowChangeMobile = [[self objectOrNilForKey:kMOSecurityDataAllowChangeMobile fromDictionary:dict] boolValue];
- self.allowChangeEmail = [[self objectOrNilForKey:kMOSecurityDataAllowChangeEmail fromDictionary:dict] boolValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.email forKey:kMOSecurityDataEmail];
- [mutableDict setValue:[NSNumber numberWithBool:self.paymentPwd] forKey:kMOSecurityDataPaymentPwd];
- [mutableDict setValue:[NSNumber numberWithBool:self.loginPwd] forKey:kMOSecurityDataLoginPwd];
- [mutableDict setValue:[NSNumber numberWithDouble:self.level] forKey:kMOSecurityDataLevel];
- [mutableDict setValue:[self.mobileInfo dictionaryRepresentation] forKey:kMOSecurityDataMobileInfo];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.allowChangeMobile] forKey:kMOSecurityDataAllowChangeMobile];
- [mutableDict setValue:[NSNumber numberWithBool:self.allowChangeEmail] forKey:kMOSecurityDataAllowChangeEmail];
- 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.email = [aDecoder decodeObjectForKey:kMOSecurityDataEmail];
- self.paymentPwd = [aDecoder decodeBoolForKey:kMOSecurityDataPaymentPwd];
- self.loginPwd = [aDecoder decodeBoolForKey:kMOSecurityDataLoginPwd];
- self.level = [aDecoder decodeDoubleForKey:kMOSecurityDataLevel];
- self.mobileInfo = [aDecoder decodeObjectForKey:kMOSecurityDataMobileInfo];
-
- self.allowChangeMobile = [aDecoder decodeBoolForKey:kMOSecurityDataAllowChangeMobile];
- self.allowChangeEmail = [aDecoder decodeBoolForKey:kMOSecurityDataAllowChangeEmail];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_email forKey:kMOSecurityDataEmail];
- [aCoder encodeBool:_paymentPwd forKey:kMOSecurityDataPaymentPwd];
- [aCoder encodeBool:_loginPwd forKey:kMOSecurityDataLoginPwd];
- [aCoder encodeDouble:_level forKey:kMOSecurityDataLevel];
- [aCoder encodeObject:_mobileInfo forKey:kMOSecurityDataMobileInfo];
-
- [aCoder encodeBool:_allowChangeMobile forKey:kMOSecurityDataAllowChangeMobile];
- [aCoder encodeBool:_allowChangeEmail forKey:kMOSecurityDataAllowChangeEmail];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOSecurityData *copy = [[MOSecurityData alloc] init];
-
-
-
- if (copy) {
- copy.email = [self.email copyWithZone:zone];
- copy.paymentPwd = self.paymentPwd;
- copy.loginPwd = self.loginPwd;
- copy.level = self.level;
- copy.mobileInfo = [self.mobileInfo copyWithZone:zone];
-
- copy.allowChangeMobile = self.allowChangeMobile;
- copy.allowChangeEmail = self.allowChangeEmail;
- }
-
- return copy;
- }
- @end
|