| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // MOGiftPackItems.m
- //
- // Created by SuperCabbage on 2024/9/10
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOGiftPackItems.h"
- NSString *const kMOGiftPackItemsAmount = @"amount";
- NSString *const kMOGiftPackItemsIcon = @"icon";
- NSString *const kMOGiftPackItemsForever = @"forever";
- NSString *const kMOGiftPackItemsType = @"type";
- NSString *const kMOGiftPackItemsName = @"name";
- NSString *const kMOGiftPackItemsDesc = @"desc";
- @interface MOGiftPackItems ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOGiftPackItems
- @synthesize amount = _amount;
- @synthesize icon = _icon;
- @synthesize forever = _forever;
- @synthesize type = _type;
- @synthesize name = _name;
- @synthesize desc = _desc;
- + (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.amount = [[self objectOrNilForKey:kMOGiftPackItemsAmount fromDictionary:dict] doubleValue];
- self.icon = [self objectOrNilForKey:kMOGiftPackItemsIcon fromDictionary:dict];
- self.forever = [[self objectOrNilForKey:kMOGiftPackItemsForever fromDictionary:dict] boolValue];
- self.type = [[self objectOrNilForKey:kMOGiftPackItemsType fromDictionary:dict] doubleValue];
- self.name = [self objectOrNilForKey:kMOGiftPackItemsName fromDictionary:dict];
- self.desc = [self objectOrNilForKey:kMOGiftPackItemsDesc fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOGiftPackItemsAmount];
- [mutableDict setValue:self.icon forKey:kMOGiftPackItemsIcon];
- [mutableDict setValue:[NSNumber numberWithBool:self.forever] forKey:kMOGiftPackItemsForever];
- [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMOGiftPackItemsType];
- [mutableDict setValue:self.name forKey:kMOGiftPackItemsName];
- [mutableDict setValue:self.desc forKey:kMOGiftPackItemsDesc];
- 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.amount = [aDecoder decodeDoubleForKey:kMOGiftPackItemsAmount];
- self.icon = [aDecoder decodeObjectForKey:kMOGiftPackItemsIcon];
- self.forever = [aDecoder decodeBoolForKey:kMOGiftPackItemsForever];
- self.type = [aDecoder decodeDoubleForKey:kMOGiftPackItemsType];
- self.name = [aDecoder decodeObjectForKey:kMOGiftPackItemsName];
- self.desc = [aDecoder decodeObjectForKey:kMOGiftPackItemsDesc];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_amount forKey:kMOGiftPackItemsAmount];
- [aCoder encodeObject:_icon forKey:kMOGiftPackItemsIcon];
- [aCoder encodeBool:_forever forKey:kMOGiftPackItemsForever];
- [aCoder encodeDouble:_type forKey:kMOGiftPackItemsType];
- [aCoder encodeObject:_name forKey:kMOGiftPackItemsName];
- [aCoder encodeObject:_desc forKey:kMOGiftPackItemsDesc];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOGiftPackItems *copy = [[MOGiftPackItems alloc] init];
-
-
-
- if (copy) {
- copy.amount = self.amount;
- copy.icon = [self.icon copyWithZone:zone];
- copy.forever = self.forever;
- copy.type = self.type;
- copy.name = [self.name copyWithZone:zone];
- copy.desc = [self.desc copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|