| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // MOHelpList.m
- //
- // Created by SuperCabbage on 2023/11/22
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOHelpList.h"
- #import "MOUserProfile.h"
- NSString *const kMOHelpListNum = @"num";
- NSString *const kMOHelpListUser = @"user";
- @interface MOHelpList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOHelpList
- @synthesize num = _num;
- @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.num = [[self objectOrNilForKey:kMOHelpListNum fromDictionary:dict] doubleValue];
- self.user = [MOUserProfile modelObjectWithDictionary:[dict objectForKey:kMOHelpListUser]];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[NSNumber numberWithDouble:self.num] forKey:kMOHelpListNum];
- [mutableDict setValue:[self.user dictionaryRepresentation] forKey:kMOHelpListUser];
- 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.num = [aDecoder decodeDoubleForKey:kMOHelpListNum];
- self.user = [aDecoder decodeObjectForKey:kMOHelpListUser];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeDouble:_num forKey:kMOHelpListNum];
- [aCoder encodeObject:_user forKey:kMOHelpListUser];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOHelpList *copy = [[MOHelpList alloc] init];
-
-
-
- if (copy) {
- copy.num = self.num;
- copy.user = [self.user copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|