| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // MOJumpList.m
- //
- // Created by SuperCabbage on 2024/3/20
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOJumpList.h"
- NSString *const kMOJumpListImg = @"img";
- NSString *const kMOJumpListJump = @"jump";
- NSString *const kMOJumpListTarget = @"target";
- NSString *const kMOJumpListTitle = @"title";
- NSString *const kMOJumpListIcon = @"icon";
- NSString *const kMOJumpListEndTime = @"endTime";
- @interface MOJumpList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOJumpList
- @synthesize img = _img;
- @synthesize jump = _jump;
- @synthesize target = _target;
- @synthesize title = _title;
- @synthesize icon = _icon;
- @synthesize endTime = _endTime;
- + (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.img = [self objectOrNilForKey:kMOJumpListImg fromDictionary:dict];
- self.jump = [self objectOrNilForKey:kMOJumpListJump fromDictionary:dict];
- self.target = [[self objectOrNilForKey:kMOJumpListTarget fromDictionary:dict] doubleValue];
- self.title = [self objectOrNilForKey:kMOJumpListTitle fromDictionary:dict];
-
- self.icon = [self objectOrNilForKey:kMOJumpListIcon fromDictionary:dict];
- self.endTime = [[self objectOrNilForKey:kMOJumpListEndTime fromDictionary:dict] doubleValue];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.img forKey:kMOJumpListImg];
- [mutableDict setValue:self.jump forKey:kMOJumpListJump];
- [mutableDict setValue:[NSNumber numberWithDouble:self.target] forKey:kMOJumpListTarget];
- [mutableDict setValue:self.title forKey:kMOJumpListTitle];
-
- [mutableDict setValue:self.icon forKey:kMOJumpListIcon];
- [mutableDict setValue:[NSNumber numberWithDouble:self.endTime] forKey:kMOJumpListEndTime];
- 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.img = [aDecoder decodeObjectForKey:kMOJumpListImg];
- self.jump = [aDecoder decodeObjectForKey:kMOJumpListJump];
- self.target = [aDecoder decodeDoubleForKey:kMOJumpListTarget];
- self.title = [aDecoder decodeObjectForKey:kMOJumpListTitle];
-
- self.icon = [aDecoder decodeObjectForKey:kMOJumpListIcon];
- self.endTime = [aDecoder decodeDoubleForKey:kMOJumpListEndTime];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_img forKey:kMOJumpListImg];
- [aCoder encodeObject:_jump forKey:kMOJumpListJump];
- [aCoder encodeDouble:_target forKey:kMOJumpListTarget];
- [aCoder encodeObject:_title forKey:kMOJumpListTitle];
-
- [aCoder encodeObject:_icon forKey:kMOJumpListIcon];
- [aCoder encodeDouble:_endTime forKey:kMOJumpListEndTime];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOJumpList *copy = [[MOJumpList alloc] init];
-
-
-
- if (copy) {
- copy.img = [self.img copyWithZone:zone];
- copy.jump = [self.jump copyWithZone:zone];
- copy.target = self.target;
- copy.title = [self.title copyWithZone:zone];
-
- copy.icon = [self.icon copyWithZone:zone];
- copy.endTime = self.endTime;
- }
-
- return copy;
- }
- @end
|