| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // MOUserGift.m
- //
- // Created by 青天 猫 on 2025/6/9
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MOUserGift.h"
- NSString *const kMOUserGiftImage = @"image";
- NSString *const kMOUserGiftName = @"name";
- NSString *const kMOUserGiftType = @"type";
- NSString *const kMOUserGiftAmount = @"amount";
- @interface MOUserGift ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOUserGift
- @synthesize image = _image;
- @synthesize name = _name;
- @synthesize type = _type;
- @synthesize amount = _amount;
- + (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.image = [self objectOrNilForKey:kMOUserGiftImage fromDictionary:dict];
- self.name = [self objectOrNilForKey:kMOUserGiftName fromDictionary:dict];
- self.type = [[self objectOrNilForKey:kMOUserGiftType fromDictionary:dict] integerValue];
- self.amount = [[self objectOrNilForKey:kMOUserGiftAmount fromDictionary:dict] integerValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.image forKey:kMOUserGiftImage];
- [mutableDict setValue:self.name forKey:kMOUserGiftName];
- [mutableDict setValue:[NSNumber numberWithInteger:self.type] forKey:kMOUserGiftType];
- [mutableDict setValue:[NSNumber numberWithInteger:self.amount] forKey:kMOUserGiftAmount];
- 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.image = [aDecoder decodeObjectForKey:kMOUserGiftImage];
- self.name = [aDecoder decodeObjectForKey:kMOUserGiftName];
- self.type = [aDecoder decodeIntegerForKey:kMOUserGiftType];
- self.amount = [aDecoder decodeIntegerForKey:kMOUserGiftAmount];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_image forKey:kMOUserGiftImage];
- [aCoder encodeObject:_name forKey:kMOUserGiftName];
- [aCoder encodeInteger:_type forKey:kMOUserGiftType];
- [aCoder encodeInteger:_amount forKey:kMOUserGiftAmount];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOUserGift *copy = [[MOUserGift alloc] init];
-
-
-
- if (copy) {
- copy.image = [self.image copyWithZone:zone];
- copy.name = [self.name copyWithZone:zone];
- copy.type = self.type;
- copy.amount = self.amount;
- }
-
- return copy;
- }
- @end
|