// // MOSignPrizes.m // // Created by SuperCabbage on 2024/5/31 // Copyright (c) 2024 __MyCompanyName__. All rights reserved. // #import "MOSignPrizes.h" NSString *const kMOSignPrizesAmount = @"amount"; NSString *const kMOSignPrizesIcon = @"icon"; NSString *const kMOSignPrizesType = @"type"; NSString *const kMOSignPrizesName = @"name"; NSString *const kMOSignPrizesTag = @"tag"; @interface MOSignPrizes () - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict; @end @implementation MOSignPrizes @synthesize amount = _amount; @synthesize icon = _icon; @synthesize type = _type; @synthesize name = _name; @synthesize tag = _tag; + (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:kMOSignPrizesAmount fromDictionary:dict] doubleValue]; self.icon = [self objectOrNilForKey:kMOSignPrizesIcon fromDictionary:dict]; self.type = [[self objectOrNilForKey:kMOSignPrizesType fromDictionary:dict] doubleValue]; self.name = [self objectOrNilForKey:kMOSignPrizesName fromDictionary:dict]; self.tag = [[self objectOrNilForKey:kMOSignPrizesTag fromDictionary:dict] doubleValue]; } return self; } - (NSDictionary *)dictionaryRepresentation { NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary]; [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOSignPrizesAmount]; [mutableDict setValue:self.icon forKey:kMOSignPrizesIcon]; [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMOSignPrizesType]; [mutableDict setValue:self.name forKey:kMOSignPrizesName]; [mutableDict setValue:[NSNumber numberWithDouble:self.tag] forKey:kMOSignPrizesTag]; 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:kMOSignPrizesAmount]; self.icon = [aDecoder decodeObjectForKey:kMOSignPrizesIcon]; self.type = [aDecoder decodeDoubleForKey:kMOSignPrizesType]; self.name = [aDecoder decodeObjectForKey:kMOSignPrizesName]; self.tag = [aDecoder decodeDoubleForKey:kMOSignPrizesTag]; return self; } - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeDouble:_amount forKey:kMOSignPrizesAmount]; [aCoder encodeObject:_icon forKey:kMOSignPrizesIcon]; [aCoder encodeDouble:_type forKey:kMOSignPrizesType]; [aCoder encodeObject:_name forKey:kMOSignPrizesName]; [aCoder encodeDouble:_tag forKey:kMOSignPrizesTag]; } - (id)copyWithZone:(NSZone *)zone { MOSignPrizes *copy = [[MOSignPrizes alloc] init]; if (copy) { copy.amount = self.amount; copy.icon = [self.icon copyWithZone:zone]; copy.type = self.type; copy.name = [self.name copyWithZone:zone]; copy.tag = self.tag; } return copy; } @end