82 lines
2.5 KiB
Objective-C
82 lines
2.5 KiB
Objective-C
//
|
|
// InviteCodeModelDataModel.m
|
|
//
|
|
// Created by Yao on 2024/11/9
|
|
// Copyright (c) 2024 zL. All rights reserved.
|
|
//
|
|
|
|
#import "InviteCodeModelDataModel.h"
|
|
#import "InviteCodeModelData.h"
|
|
|
|
NSString *const kInviteCodeModelDataModelData = @"data";
|
|
NSString *const kInviteCodeModelDataModelCode = @"code";
|
|
|
|
@interface InviteCodeModelDataModel ()
|
|
|
|
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
|
|
|
|
@end
|
|
|
|
@implementation InviteCodeModelDataModel
|
|
|
|
@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 = [InviteCodeModelData modelObjectWithDictionary:[dict objectForKey:kInviteCodeModelDataModelData]];
|
|
self.code = [[self objectOrNilForKey:kInviteCodeModelDataModelCode fromDictionary:dict] intValue];
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSDictionary *)dictionaryRepresentation {
|
|
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
|
|
[mutableDict setValue:[self.data dictionaryRepresentation] forKey:kInviteCodeModelDataModelData];
|
|
[mutableDict setValue:[NSNumber numberWithInteger:self.code] forKey:kInviteCodeModelDataModelCode];
|
|
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:kInviteCodeModelDataModelData];
|
|
self.code = [aDecoder decodeIntegerForKey:kInviteCodeModelDataModelCode];
|
|
return self;
|
|
}
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
|
[aCoder encodeObject:_data forKey:kInviteCodeModelDataModelData];
|
|
[aCoder encodeInteger:_code forKey:kInviteCodeModelDataModelCode];
|
|
}
|
|
|
|
- (id)copyWithZone:(NSZone *)zone {
|
|
InviteCodeModelDataModel *copy = [[InviteCodeModelDataModel alloc] init];
|
|
if (copy) {
|
|
copy.data = [self.data copyWithZone:zone];
|
|
copy.code = self.code;
|
|
}
|
|
return copy;
|
|
}
|
|
|
|
@end
|