| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // MOFanTasksList.m
- //
- // Created by SuperCabbage on 2024/5/30
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOFanTasksList.h"
- #import "MOFanTaskInfo.h"
- NSString *const kMOFanTasksListValue = @"value";
- NSString *const kMOFanTasksListFanTaskInfo = @"info";
- @interface MOFanTasksList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOFanTasksList
- @synthesize value = _value;
- @synthesize fanTaskInfo = _fanTaskInfo;
- + (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.value = [[self objectOrNilForKey:kMOFanTasksListValue fromDictionary:dict] doubleValue];
- self.fanTaskInfo = [MOFanTaskInfo modelObjectWithDictionary:[dict objectForKey:kMOFanTasksListFanTaskInfo]];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.value] forKey:kMOFanTasksListValue];
- [mutableDict setValue:[self.fanTaskInfo dictionaryRepresentation] forKey:kMOFanTasksListFanTaskInfo];
- 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.value = [aDecoder decodeDoubleForKey:kMOFanTasksListValue];
- self.fanTaskInfo = [aDecoder decodeObjectForKey:kMOFanTasksListFanTaskInfo];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_value forKey:kMOFanTasksListValue];
- [aCoder encodeObject:_fanTaskInfo forKey:kMOFanTasksListFanTaskInfo];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOFanTasksList *copy = [[MOFanTasksList alloc] init];
-
-
-
- if (copy) {
- copy.value = self.value;
- copy.fanTaskInfo = [self.fanTaskInfo copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|