| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // MORankHit.m
- //
- // Created by 青天 猫 on 2025/9/11
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MORankHit.h"
- NSString *const kMORankHitGiftName = @"giftName";
- NSString *const kMORankHitGiftImg = @"giftImg";
- NSString *const kMORankHitHitAmount = @"hitAmount";
- NSString *const kMORankHitGiftId = @"giftId";
- NSString *const kMORankHitGiftCategory = @"giftCategory";
- NSString *const kMORankHitHitType = @"hitType";
- @interface MORankHit ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MORankHit
- @synthesize giftName = _giftName;
- @synthesize giftImg = _giftImg;
- @synthesize hitAmount = _hitAmount;
- @synthesize giftId = _giftId;
- @synthesize giftCategory = _giftCategory;
- @synthesize hitType = _hitType;
- + (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.giftName = [self objectOrNilForKey:kMORankHitGiftName fromDictionary:dict];
- self.giftImg = [self objectOrNilForKey:kMORankHitGiftImg fromDictionary:dict];
- self.hitAmount = [[self objectOrNilForKey:kMORankHitHitAmount fromDictionary:dict] doubleValue];
- self.giftId = [self objectOrNilForKey:kMORankHitGiftId fromDictionary:dict];
- self.giftCategory = [[self objectOrNilForKey:kMORankHitGiftCategory fromDictionary:dict] doubleValue];
- self.hitType = [[self objectOrNilForKey:kMORankHitHitType fromDictionary:dict] doubleValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.giftName forKey:kMORankHitGiftName];
- [mutableDict setValue:self.giftImg forKey:kMORankHitGiftImg];
- [mutableDict setValue:[NSNumber numberWithDouble:self.hitAmount] forKey:kMORankHitHitAmount];
- [mutableDict setValue:self.giftId forKey:kMORankHitGiftId];
- [mutableDict setValue:[NSNumber numberWithDouble:self.giftCategory] forKey:kMORankHitGiftCategory];
- [mutableDict setValue:[NSNumber numberWithDouble:self.hitType] forKey:kMORankHitHitType];
- 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.giftName = [aDecoder decodeObjectForKey:kMORankHitGiftName];
- self.giftImg = [aDecoder decodeObjectForKey:kMORankHitGiftImg];
- self.hitAmount = [aDecoder decodeDoubleForKey:kMORankHitHitAmount];
- self.giftId = [aDecoder decodeObjectForKey:kMORankHitGiftId];
- self.giftCategory = [aDecoder decodeDoubleForKey:kMORankHitGiftCategory];
- self.hitType = [aDecoder decodeDoubleForKey:kMORankHitHitType];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_giftName forKey:kMORankHitGiftName];
- [aCoder encodeObject:_giftImg forKey:kMORankHitGiftImg];
- [aCoder encodeDouble:_hitAmount forKey:kMORankHitHitAmount];
- [aCoder encodeObject:_giftId forKey:kMORankHitGiftId];
- [aCoder encodeDouble:_giftCategory forKey:kMORankHitGiftCategory];
- [aCoder encodeDouble:_hitType forKey:kMORankHitHitType];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MORankHit *copy = [[MORankHit alloc] init];
-
-
-
- if (copy) {
- copy.giftName = [self.giftName copyWithZone:zone];
- copy.giftImg = [self.giftImg copyWithZone:zone];
- copy.hitAmount = self.hitAmount;
- copy.giftId = [self.giftId copyWithZone:zone];
- copy.giftCategory = self.giftCategory;
- copy.hitType = self.hitType;
- }
-
- return copy;
- }
- @end
|