| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // MOBaseVips.m
- //
- // Created by SuperCabbage on 2025/1/10
- // Copyright (c) 2025 __MyCompanyName__. All rights reserved.
- //
- #import "MOBaseVips.h"
- NSString *const kMOBaseVipsIcon = @"icon";
- NSString *const kMOBaseVipsType = @"type";
- NSString *const kMOBaseVipsImage = @"image";
- NSString *const kMOBaseVipsThumbnail = @"thumbnail";
- NSString *const kMOBaseVipsEntryBg = @"entryBg";
- @interface MOBaseVips ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOBaseVips
- @synthesize icon = _icon;
- @synthesize type = _type;
- @synthesize image = _image;
- @synthesize thumbnail = _thumbnail;
- @synthesize entryBg = _entryBg;
- + (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.icon = [self objectOrNilForKey:kMOBaseVipsIcon fromDictionary:dict];
- self.type = [[self objectOrNilForKey:kMOBaseVipsType fromDictionary:dict] doubleValue];
- self.image = [self objectOrNilForKey:kMOBaseVipsImage fromDictionary:dict];
- self.thumbnail = [self objectOrNilForKey:kMOBaseVipsThumbnail fromDictionary:dict];
-
- self.entryBg = [self objectOrNilForKey:kMOBaseVipsEntryBg fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.icon forKey:kMOBaseVipsIcon];
- [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMOBaseVipsType];
- [mutableDict setValue:self.image forKey:kMOBaseVipsImage];
- [mutableDict setValue:self.thumbnail forKey:kMOBaseVipsThumbnail];
-
- [mutableDict setValue:self.entryBg forKey:kMOBaseVipsEntryBg];
- 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.icon = [aDecoder decodeObjectForKey:kMOBaseVipsIcon];
- self.type = [aDecoder decodeDoubleForKey:kMOBaseVipsType];
- self.image = [aDecoder decodeObjectForKey:kMOBaseVipsImage];
- self.thumbnail = [aDecoder decodeObjectForKey:kMOBaseVipsThumbnail];
-
- self.entryBg = [aDecoder decodeObjectForKey:kMOBaseVipsEntryBg];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_icon forKey:kMOBaseVipsIcon];
- [aCoder encodeDouble:_type forKey:kMOBaseVipsType];
- [aCoder encodeObject:_image forKey:kMOBaseVipsImage];
- [aCoder encodeObject:_thumbnail forKey:kMOBaseVipsThumbnail];
-
- [aCoder encodeObject:_entryBg forKey:kMOBaseVipsEntryBg];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOBaseVips *copy = [[MOBaseVips alloc] init];
-
-
-
- if (copy) {
- copy.icon = [self.icon copyWithZone:zone];
- copy.type = self.type;
- copy.image = [self.image copyWithZone:zone];
- copy.thumbnail = [self.thumbnail copyWithZone:zone];
-
- copy.entryBg = [self.entryBg copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|