| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- //
- // MOPkUserList.m
- //
- // Created by SuperCabbage on 2023/12/18
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOPkUserList.h"
- #import "MOUserProfile.h"
- NSString *const kMOPkUserListRoomId = @"roomId";
- NSString *const kMOPkUserListWinNum = @"winNum";
- NSString *const kMOPkUserListPkNum = @"pkNum";
- NSString *const kMOPkUserListWinRate = @"winRate";
- NSString *const kMOPkUserListUserProfile = @"user";
- NSString *const kMOPkUserListPkSecret = @"pkSecret";
- NSString *const kMOPkUserListAmount = @"amount";
- NSString *const kMOPkUserListInvite = @"invite";
- @interface MOPkUserList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOPkUserList
- @synthesize roomId = _roomId;
- @synthesize winNum = _winNum;
- @synthesize pkNum = _pkNum;
- @synthesize winRate = _winRate;
- @synthesize userProfile = _userProfile;
- @synthesize pkSecret = _pkSecret;
- @synthesize amount = _amount;
- @synthesize invite = _invite;
- + (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.roomId = [self objectOrNilForKey:kMOPkUserListRoomId fromDictionary:dict];
- self.winNum = [[self objectOrNilForKey:kMOPkUserListWinNum fromDictionary:dict] doubleValue];
- self.pkNum = [[self objectOrNilForKey:kMOPkUserListPkNum fromDictionary:dict] doubleValue];
- self.winRate = [[self objectOrNilForKey:kMOPkUserListWinRate fromDictionary:dict] doubleValue];
- self.userProfile = [MOUserProfile modelObjectWithDictionary:[dict objectForKey:kMOPkUserListUserProfile]];
-
- self.pkSecret = [self objectOrNilForKey:kMOPkUserListPkSecret fromDictionary:dict];
-
- self.amount = [[self objectOrNilForKey:kMOPkUserListAmount fromDictionary:dict] doubleValue];
-
- self.invite = [self objectOrNilForKey:kMOPkUserListInvite fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:self.roomId forKey:kMOPkUserListRoomId];
- [mutableDict setValue:[NSNumber numberWithDouble:self.winNum] forKey:kMOPkUserListWinNum];
- [mutableDict setValue:[NSNumber numberWithDouble:self.pkNum] forKey:kMOPkUserListPkNum];
- [mutableDict setValue:[NSNumber numberWithDouble:self.winRate] forKey:kMOPkUserListWinRate];
- [mutableDict setValue:[self.userProfile dictionaryRepresentation] forKey:kMOPkUserListUserProfile];
-
- [mutableDict setValue:self.pkSecret forKey:kMOPkUserListPkSecret];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOPkUserListAmount];
-
- [mutableDict setValue:self.invite forKey:kMOPkUserListInvite];
- 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.roomId = [aDecoder decodeObjectForKey:kMOPkUserListRoomId];
- self.winNum = [aDecoder decodeDoubleForKey:kMOPkUserListWinNum];
- self.pkNum = [aDecoder decodeDoubleForKey:kMOPkUserListPkNum];
- self.winRate = [aDecoder decodeDoubleForKey:kMOPkUserListWinRate];
- self.userProfile = [aDecoder decodeObjectForKey:kMOPkUserListUserProfile];
-
- self.pkSecret = [aDecoder decodeObjectForKey:kMOPkUserListPkSecret];
-
- self.amount = [aDecoder decodeDoubleForKey:kMOPkUserListAmount];
-
- self.invite = [aDecoder decodeObjectForKey:kMOPkUserListInvite];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_roomId forKey:kMOPkUserListRoomId];
- [aCoder encodeDouble:_winNum forKey:kMOPkUserListWinNum];
- [aCoder encodeDouble:_pkNum forKey:kMOPkUserListPkNum];
- [aCoder encodeDouble:_winRate forKey:kMOPkUserListWinRate];
- [aCoder encodeObject:_userProfile forKey:kMOPkUserListUserProfile];
-
- [aCoder encodeObject:_pkSecret forKey:kMOPkUserListPkSecret];
-
- [aCoder encodeDouble:_amount forKey:kMOPkUserListAmount];
- [aCoder encodeObject:_invite forKey:kMOPkUserListInvite];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOPkUserList *copy = [[MOPkUserList alloc] init];
-
-
-
- if (copy) {
- copy.roomId = [self.roomId copyWithZone:zone];
- copy.winNum = self.winNum;
- copy.pkNum = self.pkNum;
- copy.winRate = self.winRate;
- copy.userProfile = [self.userProfile copyWithZone:zone];
-
- copy.pkSecret = [self.pkSecret copyWithZone:zone];
- copy.amount = self.amount;
- copy.invite = [self.invite copyWithZone:zone];
- copy.isSelect = self.isSelect;
- }
-
- return copy;
- }
- @end
|