| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // MORankMe.m
- //
- // Created by 青天 猫 on 2025/9/11
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MORankMe.h"
- #import "MOUserBase.h"
- NSString *const kMORankMeIdx = @"idx";
- NSString *const kMORankMeTotal = @"total";
- NSString *const kMORankMeUser = @"user";
- @interface MORankMe ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MORankMe
- @synthesize idx = _idx;
- @synthesize total = _total;
- @synthesize user = _user;
- + (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.idx = [[self objectOrNilForKey:kMORankMeIdx fromDictionary:dict] doubleValue];
- self.total = [[self objectOrNilForKey:kMORankMeTotal fromDictionary:dict] doubleValue];
- self.user = [MOUserBase modelObjectWithDictionary:[dict objectForKey:kMORankMeUser]];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.idx] forKey:kMORankMeIdx];
- [mutableDict setValue:[NSNumber numberWithDouble:self.total] forKey:kMORankMeTotal];
- [mutableDict setValue:[self.user dictionaryRepresentation] forKey:kMORankMeUser];
- 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.idx = [aDecoder decodeDoubleForKey:kMORankMeIdx];
- self.total = [aDecoder decodeDoubleForKey:kMORankMeTotal];
- self.user = [aDecoder decodeObjectForKey:kMORankMeUser];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_idx forKey:kMORankMeIdx];
- [aCoder encodeDouble:_total forKey:kMORankMeTotal];
- [aCoder encodeObject:_user forKey:kMORankMeUser];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MORankMe *copy = [[MORankMe alloc] init];
-
-
-
- if (copy) {
- copy.idx = self.idx;
- copy.total = self.total;
- copy.user = [self.user copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|