Files
WebApp/ShenQi/YYModel/ConfigData.m
2024-12-25 09:41:16 +08:00

184 lines
9.1 KiB
Objective-C

//
// ConfigData.m
//
// Created by Yao on 2024/12/19
// Copyright (c) 2024 zL. All rights reserved.
//
#import "ConfigData.h"
NSString *const kConfigDataDescription = @"description";
NSString *const kConfigDataIosVersionCode = @"iosVersionCode";
NSString *const kConfigDataForceUpdate = @"forceUpdate";
NSString *const kConfigDataFbUrl = @"fbUrl";
NSString *const kConfigDataCredentials = @"credentials";
NSString *const kConfigDataUrl = @"url";
NSString *const kConfigDataInviteFee = @"inviteFee";
NSString *const kConfigDataUserId = @"userId";
NSString *const kConfigDataContactApplyMode = @"contactApplyMode";
NSString *const kConfigDataVersionCode = @"versionCode";
NSString *const kConfigDataTgUrl = @"tgUrl";
NSString *const kConfigDataNoticeApplyMode = @"noticeApplyMode";
NSString *const kConfigDataWsUrl = @"wsUrl";
NSString *const kConfigDataApkUrl = @"apkUrl";
NSString *const kConfigDataDownloadUrl = @"downloadUrl";
NSString *const kConfigDataIsUse = @"isUse";
NSString *const kConfigDatalinkConfig = @"linkConfig";
@interface ConfigData ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation ConfigData
@synthesize description = _description;
@synthesize iosVersionCode = _iosVersionCode;
@synthesize forceUpdate = _forceUpdate;
@synthesize fbUrl = _fbUrl;
@synthesize credentials = _credentials;
@synthesize url = _url;
@synthesize inviteFee = _inviteFee;
@synthesize userId = _userId;
@synthesize contactApplyMode = _contactApplyMode;
@synthesize versionCode = _versionCode;
@synthesize tgUrl = _tgUrl;
@synthesize noticeApplyMode = _noticeApplyMode;
@synthesize wsUrl = _wsUrl;
@synthesize apkUrl = _apkUrl;
@synthesize downloadUrl = _downloadUrl;
@synthesize isUse = _isUse;
@synthesize linkConfig = _linkConfig;
+ (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.description = [self objectOrNilForKey:kConfigDataDescription fromDictionary:dict];
self.iosVersionCode = [self objectOrNilForKey:kConfigDataIosVersionCode fromDictionary:dict];
self.forceUpdate = [[self objectOrNilForKey:kConfigDataForceUpdate fromDictionary:dict] intValue];
self.fbUrl = [self objectOrNilForKey:kConfigDataFbUrl fromDictionary:dict];
self.credentials = [self objectOrNilForKey:kConfigDataCredentials fromDictionary:dict];
self.url = [self objectOrNilForKey:kConfigDataUrl fromDictionary:dict];
self.inviteFee = [[self objectOrNilForKey:kConfigDataInviteFee fromDictionary:dict] doubleValue];
self.userId = [[self objectOrNilForKey:kConfigDataUserId fromDictionary:dict] intValue];
self.contactApplyMode = [[self objectOrNilForKey:kConfigDataContactApplyMode fromDictionary:dict] intValue];
self.versionCode = [self objectOrNilForKey:kConfigDataVersionCode fromDictionary:dict];
self.tgUrl = [self objectOrNilForKey:kConfigDataTgUrl fromDictionary:dict];
self.noticeApplyMode = [[self objectOrNilForKey:kConfigDataNoticeApplyMode fromDictionary:dict] intValue];
self.wsUrl = [self objectOrNilForKey:kConfigDataWsUrl fromDictionary:dict];
self.apkUrl = [self objectOrNilForKey:kConfigDataApkUrl fromDictionary:dict];
self.downloadUrl = [self objectOrNilForKey:kConfigDataDownloadUrl fromDictionary:dict];
self.isUse = [[self objectOrNilForKey:kConfigDataIsUse fromDictionary:dict] intValue];
self.linkConfig = [self objectOrNilForKey:kConfigDatalinkConfig fromDictionary:dict]; }
return self;
}
- (NSDictionary *)dictionaryRepresentation {
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict setValue:self.description forKey:kConfigDataDescription];
[mutableDict setValue:self.iosVersionCode forKey:kConfigDataIosVersionCode];
[mutableDict setValue:[NSNumber numberWithInteger:self.forceUpdate] forKey:kConfigDataForceUpdate];
[mutableDict setValue:self.fbUrl forKey:kConfigDataFbUrl];
[mutableDict setValue:self.credentials forKey:kConfigDataCredentials];
[mutableDict setValue:self.url forKey:kConfigDataUrl];
[mutableDict setValue:[NSNumber numberWithDouble:self.inviteFee] forKey:kConfigDataInviteFee];
[mutableDict setValue:[NSNumber numberWithInteger:self.userId] forKey:kConfigDataUserId];
[mutableDict setValue:[NSNumber numberWithInteger:self.contactApplyMode] forKey:kConfigDataContactApplyMode];
[mutableDict setValue:self.versionCode forKey:kConfigDataVersionCode];
[mutableDict setValue:self.tgUrl forKey:kConfigDataTgUrl];
[mutableDict setValue:[NSNumber numberWithInteger:self.noticeApplyMode] forKey:kConfigDataNoticeApplyMode];
[mutableDict setValue:self.wsUrl forKey:kConfigDataWsUrl];
[mutableDict setValue:self.apkUrl forKey:kConfigDataApkUrl];
[mutableDict setValue:self.downloadUrl forKey:kConfigDataDownloadUrl];
[mutableDict setValue:self.linkConfig forKey:kConfigDataDownloadUrl];
[mutableDict setValue:[NSNumber numberWithInteger:self.isUse] forKey:kConfigDataIsUse];
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.description = [aDecoder decodeObjectForKey:kConfigDataDescription];
self.iosVersionCode = [aDecoder decodeObjectForKey:kConfigDataIosVersionCode];
self.forceUpdate = [aDecoder decodeIntegerForKey:kConfigDataForceUpdate];
self.fbUrl = [aDecoder decodeObjectForKey:kConfigDataFbUrl];
self.credentials = [aDecoder decodeObjectForKey:kConfigDataCredentials];
self.url = [aDecoder decodeObjectForKey:kConfigDataUrl];
self.inviteFee = [aDecoder decodeDoubleForKey:kConfigDataInviteFee];
self.userId = [aDecoder decodeIntegerForKey:kConfigDataUserId];
self.contactApplyMode = [aDecoder decodeIntegerForKey:kConfigDataContactApplyMode];
self.versionCode = [aDecoder decodeObjectForKey:kConfigDataVersionCode];
self.tgUrl = [aDecoder decodeObjectForKey:kConfigDataTgUrl];
self.noticeApplyMode = [aDecoder decodeIntegerForKey:kConfigDataNoticeApplyMode];
self.wsUrl = [aDecoder decodeObjectForKey:kConfigDataWsUrl];
self.apkUrl = [aDecoder decodeObjectForKey:kConfigDataApkUrl];
self.downloadUrl = [aDecoder decodeObjectForKey:kConfigDataDownloadUrl];
self.linkConfig = [aDecoder decodeObjectForKey:kConfigDatalinkConfig];
self.isUse = [aDecoder decodeIntegerForKey:kConfigDataIsUse];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:_description forKey:kConfigDataDescription];
[aCoder encodeObject:_iosVersionCode forKey:kConfigDataIosVersionCode];
[aCoder encodeInteger:_forceUpdate forKey:kConfigDataForceUpdate];
[aCoder encodeObject:_fbUrl forKey:kConfigDataFbUrl];
[aCoder encodeObject:_credentials forKey:kConfigDataCredentials];
[aCoder encodeObject:_url forKey:kConfigDataUrl];
[aCoder encodeDouble:_inviteFee forKey:kConfigDataInviteFee];
[aCoder encodeInteger:_userId forKey:kConfigDataUserId];
[aCoder encodeInteger:_contactApplyMode forKey:kConfigDataContactApplyMode];
[aCoder encodeObject:_versionCode forKey:kConfigDataVersionCode];
[aCoder encodeObject:_tgUrl forKey:kConfigDataTgUrl];
[aCoder encodeInteger:_noticeApplyMode forKey:kConfigDataNoticeApplyMode];
[aCoder encodeObject:_wsUrl forKey:kConfigDataWsUrl];
[aCoder encodeObject:_apkUrl forKey:kConfigDataApkUrl];
[aCoder encodeObject:_linkConfig forKey:kConfigDatalinkConfig];
[aCoder encodeObject:_downloadUrl forKey:kConfigDataDownloadUrl];
[aCoder encodeInteger:_isUse forKey:kConfigDataIsUse];
}
- (id)copyWithZone:(NSZone *)zone {
ConfigData *copy = [[ConfigData alloc] init];
if (copy) {
copy.description = [self.description copyWithZone:zone];
copy.iosVersionCode = [self.iosVersionCode copyWithZone:zone];
copy.forceUpdate = self.forceUpdate;
copy.fbUrl = [self.fbUrl copyWithZone:zone];
copy.credentials = [self.credentials copyWithZone:zone];
copy.url = [self.url copyWithZone:zone];
copy.inviteFee = self.inviteFee;
copy.userId = self.userId;
copy.contactApplyMode = self.contactApplyMode;
copy.versionCode = [self.versionCode copyWithZone:zone];
copy.tgUrl = [self.tgUrl copyWithZone:zone];
copy.noticeApplyMode = self.noticeApplyMode;
copy.wsUrl = [self.wsUrl copyWithZone:zone];
copy.apkUrl = [self.apkUrl copyWithZone:zone];
copy.linkConfig = [self.linkConfig copyWithZone:zone];
copy.downloadUrl = [self.downloadUrl copyWithZone:zone];
copy.isUse = self.isUse;
}
return copy;
}
@end