| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //
- // MOBaseCursor.m
- //
- // Created by SuperCabbage on 2025/1/10
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MOBaseCursor.h"
- NSString *const kMOBaseCursorVip = @"vip";
- NSString *const kMOBaseCursorMedal = @"medal";
- NSString *const kMOBaseCursorLevel = @"level";
- NSString *const kMOBaseCursorGift = @"gift";
- NSString *const kMOBaseCursorProp = @"prop";
- @interface MOBaseCursor ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOBaseCursor
- @synthesize vip = _vip;
- @synthesize medal = _medal;
- @synthesize level = _level;
- @synthesize gift = _gift;
- @synthesize prop = _prop;
- + (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.vip = [[self objectOrNilForKey:kMOBaseCursorVip fromDictionary:dict] doubleValue];
- self.medal = [[self objectOrNilForKey:kMOBaseCursorMedal fromDictionary:dict] doubleValue];
- self.level = [[self objectOrNilForKey:kMOBaseCursorLevel fromDictionary:dict] doubleValue];
- self.gift = [[self objectOrNilForKey:kMOBaseCursorGift fromDictionary:dict] doubleValue];
- self.prop = [[self objectOrNilForKey:kMOBaseCursorProp fromDictionary:dict] doubleValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.vip] forKey:kMOBaseCursorVip];
- [mutableDict setValue:[NSNumber numberWithDouble:self.medal] forKey:kMOBaseCursorMedal];
- [mutableDict setValue:[NSNumber numberWithDouble:self.level] forKey:kMOBaseCursorLevel];
- [mutableDict setValue:[NSNumber numberWithDouble:self.gift] forKey:kMOBaseCursorGift];
- [mutableDict setValue:[NSNumber numberWithDouble:self.prop] forKey:kMOBaseCursorProp];
- 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.vip = [aDecoder decodeDoubleForKey:kMOBaseCursorVip];
- self.medal = [aDecoder decodeDoubleForKey:kMOBaseCursorMedal];
- self.level = [aDecoder decodeDoubleForKey:kMOBaseCursorLevel];
- self.gift = [aDecoder decodeDoubleForKey:kMOBaseCursorGift];
- self.prop = [aDecoder decodeDoubleForKey:kMOBaseCursorProp];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_vip forKey:kMOBaseCursorVip];
- [aCoder encodeDouble:_medal forKey:kMOBaseCursorMedal];
- [aCoder encodeDouble:_level forKey:kMOBaseCursorLevel];
- [aCoder encodeDouble:_gift forKey:kMOBaseCursorGift];
- [aCoder encodeDouble:_prop forKey:kMOBaseCursorProp];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOBaseCursor *copy = [[MOBaseCursor alloc] init];
-
-
-
- if (copy) {
- copy.vip = self.vip;
- copy.medal = self.medal;
- copy.level = self.level;
- copy.gift = self.gift;
- copy.prop = self.prop;
- }
-
- return copy;
- }
- @end
|