// // MOLiveCenterData.m // // Created by SuperCabbage on 2023/12/6 // Copyright (c) 2023 __MyCompanyName__. All rights reserved. // #import "MOLiveCenterData.h" #import "MOUserBase.h" NSString *const kMOLiveCenterDataMembers = @"members"; NSString *const kMOLiveCenterDataTicketGoldenBean = @"ticketGoldenBean"; NSString *const kMOLiveCenterDataPopularity = @"popularity"; NSString *const kMOLiveCenterDataGiftGoldenBean = @"giftGoldenBean"; NSString *const kMOLiveCenterDataOtherGoldenBean = @"otherGoldenBean"; NSString *const kMOLiveCenterDataFans = @"fans"; NSString *const kMOLiveCenterDataViewerNum = @"viewerNum"; NSString *const kMOLiveCenterDataMvpUser = @"mvpUser"; NSString *const kMOLiveCenterDataLikeGoldenBean = @"likeGoldenBean"; NSString *const kMOLiveCenterDataDivideGoldenBean = @"divideGoldenBean"; @interface MOLiveCenterData () - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict; @end @implementation MOLiveCenterData @synthesize members = _members; @synthesize ticketGoldenBean = _ticketGoldenBean; @synthesize popularity = _popularity; @synthesize giftGoldenBean = _giftGoldenBean; @synthesize otherGoldenBean = _otherGoldenBean; @synthesize fans = _fans; @synthesize viewerNum = _viewerNum; @synthesize mvpUser = _mvpUser; @synthesize likeGoldenBean = _likeGoldenBean; @synthesize divideGoldenBean = _divideGoldenBean; + (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.members = [[self objectOrNilForKey:kMOLiveCenterDataMembers fromDictionary:dict] doubleValue]; self.ticketGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataTicketGoldenBean fromDictionary:dict] doubleValue]; self.popularity = [[self objectOrNilForKey:kMOLiveCenterDataPopularity fromDictionary:dict] doubleValue]; self.giftGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataGiftGoldenBean fromDictionary:dict] doubleValue]; self.otherGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataOtherGoldenBean fromDictionary:dict] doubleValue]; self.fans = [[self objectOrNilForKey:kMOLiveCenterDataFans fromDictionary:dict] doubleValue]; self.viewerNum = [[self objectOrNilForKey:kMOLiveCenterDataViewerNum fromDictionary:dict] doubleValue]; self.mvpUser = [MOUserBase modelObjectWithDictionary:[dict objectForKey:kMOLiveCenterDataMvpUser]]; self.likeGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataLikeGoldenBean fromDictionary:dict] doubleValue]; self.divideGoldenBean = [[self objectOrNilForKey:kMOLiveCenterDataDivideGoldenBean fromDictionary:dict] doubleValue]; } return self; } - (NSDictionary *)dictionaryRepresentation { NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary]; [mutableDict setValue:[NSNumber numberWithDouble:self.members] forKey:kMOLiveCenterDataMembers]; [mutableDict setValue:[NSNumber numberWithDouble:self.ticketGoldenBean] forKey:kMOLiveCenterDataTicketGoldenBean]; [mutableDict setValue:[NSNumber numberWithDouble:self.popularity] forKey:kMOLiveCenterDataPopularity]; [mutableDict setValue:[NSNumber numberWithDouble:self.giftGoldenBean] forKey:kMOLiveCenterDataGiftGoldenBean]; [mutableDict setValue:[NSNumber numberWithDouble:self.otherGoldenBean] forKey:kMOLiveCenterDataOtherGoldenBean]; [mutableDict setValue:[NSNumber numberWithDouble:self.fans] forKey:kMOLiveCenterDataFans]; [mutableDict setValue:[NSNumber numberWithDouble:self.viewerNum] forKey:kMOLiveCenterDataViewerNum]; [mutableDict setValue:[self.mvpUser dictionaryRepresentation] forKey:kMOLiveCenterDataMvpUser]; [mutableDict setValue:[NSNumber numberWithDouble:self.likeGoldenBean] forKey:kMOLiveCenterDataLikeGoldenBean]; [mutableDict setValue:[NSNumber numberWithDouble:self.divideGoldenBean] forKey:kMOLiveCenterDataDivideGoldenBean]; 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.members = [aDecoder decodeDoubleForKey:kMOLiveCenterDataMembers]; self.ticketGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataTicketGoldenBean]; self.popularity = [aDecoder decodeDoubleForKey:kMOLiveCenterDataPopularity]; self.giftGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataGiftGoldenBean]; self.otherGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataOtherGoldenBean]; self.fans = [aDecoder decodeDoubleForKey:kMOLiveCenterDataFans]; self.viewerNum = [aDecoder decodeDoubleForKey:kMOLiveCenterDataViewerNum]; self.mvpUser = [aDecoder decodeObjectForKey:kMOLiveCenterDataMvpUser]; self.likeGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataGiftGoldenBean]; self.divideGoldenBean = [aDecoder decodeDoubleForKey:kMOLiveCenterDataDivideGoldenBean]; return self; } - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeDouble:_members forKey:kMOLiveCenterDataMembers]; [aCoder encodeDouble:_ticketGoldenBean forKey:kMOLiveCenterDataTicketGoldenBean]; [aCoder encodeDouble:_popularity forKey:kMOLiveCenterDataPopularity]; [aCoder encodeDouble:_giftGoldenBean forKey:kMOLiveCenterDataGiftGoldenBean]; [aCoder encodeDouble:_otherGoldenBean forKey:kMOLiveCenterDataOtherGoldenBean]; [aCoder encodeDouble:_fans forKey:kMOLiveCenterDataFans]; [aCoder encodeDouble:_viewerNum forKey:kMOLiveCenterDataViewerNum]; [aCoder encodeObject:_mvpUser forKey:kMOLiveCenterDataMvpUser]; [aCoder encodeDouble:_likeGoldenBean forKey:kMOLiveCenterDataLikeGoldenBean]; [aCoder encodeDouble:_divideGoldenBean forKey:kMOLiveCenterDataDivideGoldenBean]; } - (id)copyWithZone:(NSZone *)zone { MOLiveCenterData *copy = [[MOLiveCenterData alloc] init]; if (copy) { copy.members = self.members; copy.ticketGoldenBean = self.ticketGoldenBean; copy.popularity = self.popularity; copy.giftGoldenBean = self.giftGoldenBean; copy.otherGoldenBean = self.otherGoldenBean; copy.fans = self.fans; copy.viewerNum = self.viewerNum; copy.mvpUser = [self.mvpUser copyWithZone:zone]; copy.likeGoldenBean = self.likeGoldenBean; copy.divideGoldenBean = self.divideGoldenBean; } return copy; } @end