| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- //
- // MOReceivingInfo.m
- //
- // Created by SuperCabbage on 2024/6/19
- // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
- //
- #import "MOReceivingInfo.h"
- #import "MOReceivingUserItems.h"
- NSString *const kMOReceivingInfoReceivingUserItems = @"items";
- NSString *const kMOReceivingInfoFromUserId = @"fromUserId";
- NSString *const kMOReceivingInfoFromUserAvatar = @"fromUserAvatar";
- NSString *const kMOReceivingInfoReceivedNum = @"receivedNum";
- NSString *const kMOReceivingInfoFromUserNickname = @"fromUserNickname";
- NSString *const kMOReceivingInfoNum = @"num";
- NSString *const kMOReceivingInfoRedEnvelopeId = @"redEnvelopeId";
- NSString *const kMOReceivingInfoLastReceiveSeq = @"lastReceiveSeq";
- NSString *const kMOReceivingInfoHeaddress = @"headdress";
- NSString *const kMOReceivingInfoHeaddressAnno = @"headdressAnno";
- NSString *const kMOReceivingInfoReceivingUserList = @"list";
- NSString *const kMOReceivingInfoNext = @"next";
- @interface MOReceivingInfo ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOReceivingInfo
- @synthesize receivingUserItems = _receivingUserItems;
- @synthesize fromUserId = _fromUserId;
- @synthesize fromUserAvatar = _fromUserAvatar;
- @synthesize receivedNum = _receivedNum;
- @synthesize fromUserNickname = _fromUserNickname;
- @synthesize num = _num;
- @synthesize redEnvelopeId = _redEnvelopeId;
- @synthesize lastReceiveSeq = _lastReceiveSeq;
- @synthesize headdress = _headdress;
- @synthesize headdressAnno = _headdressAnno;
- @synthesize receivingUserList = _receivingUserList;
- @synthesize next = _next;
- + (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]]) {
- NSObject *receivedMOReceivingUserItems = [dict objectForKey:kMOReceivingInfoReceivingUserItems];
- NSMutableArray *parsedMOReceivingUserItems = [NSMutableArray array];
-
- if ([receivedMOReceivingUserItems isKindOfClass:[NSArray class]]) {
- for (NSDictionary *item in (NSArray *)receivedMOReceivingUserItems) {
- if ([item isKindOfClass:[NSDictionary class]]) {
- [parsedMOReceivingUserItems addObject:[MOReceivingUserItems modelObjectWithDictionary:item]];
- }
- }
- } else if ([receivedMOReceivingUserItems isKindOfClass:[NSDictionary class]]) {
- [parsedMOReceivingUserItems addObject:[MOReceivingUserItems modelObjectWithDictionary:(NSDictionary *)receivedMOReceivingUserItems]];
- }
- self.receivingUserItems = [NSArray arrayWithArray:parsedMOReceivingUserItems];
- self.fromUserId = [self objectOrNilForKey:kMOReceivingInfoFromUserId fromDictionary:dict];
- self.fromUserAvatar = [self objectOrNilForKey:kMOReceivingInfoFromUserAvatar fromDictionary:dict];
- self.receivedNum = [[self objectOrNilForKey:kMOReceivingInfoReceivedNum fromDictionary:dict] doubleValue];
- self.fromUserNickname = [self objectOrNilForKey:kMOReceivingInfoFromUserNickname fromDictionary:dict];
- self.num = [[self objectOrNilForKey:kMOReceivingInfoNum fromDictionary:dict] doubleValue];
- self.redEnvelopeId = [self objectOrNilForKey:kMOReceivingInfoRedEnvelopeId fromDictionary:dict];
- self.lastReceiveSeq = [[self objectOrNilForKey:kMOReceivingInfoLastReceiveSeq fromDictionary:dict] doubleValue];
-
- self.headdress = [self objectOrNilForKey:kMOReceivingInfoHeaddress fromDictionary:dict];
- self.headdressAnno = [[self objectOrNilForKey:kMOReceivingInfoHeaddressAnno fromDictionary:dict] boolValue];
-
-
- NSObject *receivedMOReceivingUserList = [dict objectForKey:kMOReceivingInfoReceivingUserList];
- NSMutableArray *parsedMOReceivingUserList = [NSMutableArray array];
-
- if ([receivedMOReceivingUserList isKindOfClass:[NSArray class]]) {
- for (NSDictionary *item in (NSArray *)receivedMOReceivingUserList) {
- if ([item isKindOfClass:[NSDictionary class]]) {
- [parsedMOReceivingUserList addObject:[MOReceivingUserItems modelObjectWithDictionary:item]];
- }
- }
- } else if ([receivedMOReceivingUserList isKindOfClass:[NSDictionary class]]) {
- [parsedMOReceivingUserList addObject:[MOReceivingUserItems modelObjectWithDictionary:(NSDictionary *)receivedMOReceivingUserList]];
- }
- self.receivingUserList = [NSArray arrayWithArray:parsedMOReceivingUserList];
- self.next = [self objectOrNilForKey:kMOReceivingInfoNext fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- NSMutableArray *tempArrayForReceivingUserItems = [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.receivingUserItems) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForReceivingUserItems addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForReceivingUserItems addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForReceivingUserItems] forKey:kMOReceivingInfoReceivingUserItems];
- [mutableDict setValue:self.fromUserId forKey:kMOReceivingInfoFromUserId];
- [mutableDict setValue:self.fromUserAvatar forKey:kMOReceivingInfoFromUserAvatar];
- [mutableDict setValue:[NSNumber numberWithDouble:self.receivedNum] forKey:kMOReceivingInfoReceivedNum];
- [mutableDict setValue:self.fromUserNickname forKey:kMOReceivingInfoFromUserNickname];
- [mutableDict setValue:[NSNumber numberWithDouble:self.num] forKey:kMOReceivingInfoNum];
- [mutableDict setValue:self.redEnvelopeId forKey:kMOReceivingInfoRedEnvelopeId];
- [mutableDict setValue:[NSNumber numberWithDouble:self.lastReceiveSeq] forKey:kMOReceivingInfoLastReceiveSeq];
-
- [mutableDict setValue:self.headdress forKey:kMOReceivingInfoHeaddress];
- [mutableDict setValue:[NSNumber numberWithBool:self.headdressAnno] forKey:kMOReceivingInfoHeaddressAnno];
-
- NSMutableArray *tempArrayForReceivingUserList = [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.receivingUserList) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForReceivingUserList addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForReceivingUserList addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForReceivingUserList] forKey:kMOReceivingInfoReceivingUserList];
- [mutableDict setValue:self.next forKey:kMOReceivingInfoNext];
- 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.receivingUserItems = [aDecoder decodeObjectForKey:kMOReceivingInfoReceivingUserItems];
- self.fromUserId = [aDecoder decodeObjectForKey:kMOReceivingInfoFromUserId];
- self.fromUserAvatar = [aDecoder decodeObjectForKey:kMOReceivingInfoFromUserAvatar];
- self.receivedNum = [aDecoder decodeDoubleForKey:kMOReceivingInfoReceivedNum];
- self.fromUserNickname = [aDecoder decodeObjectForKey:kMOReceivingInfoFromUserNickname];
- self.num = [aDecoder decodeDoubleForKey:kMOReceivingInfoNum];
- self.redEnvelopeId = [aDecoder decodeObjectForKey:kMOReceivingInfoRedEnvelopeId];
- self.lastReceiveSeq = [aDecoder decodeDoubleForKey:kMOReceivingInfoLastReceiveSeq];
-
- self.headdress = [aDecoder decodeObjectForKey:kMOReceivingInfoHeaddress];
- self.headdressAnno = [aDecoder decodeBoolForKey:kMOReceivingInfoHeaddressAnno];
-
- self.receivingUserList = [aDecoder decodeObjectForKey:kMOReceivingInfoReceivingUserList];
- self.next = [aDecoder decodeObjectForKey:kMOReceivingInfoNext];
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_receivingUserItems forKey:kMOReceivingInfoReceivingUserItems];
- [aCoder encodeObject:_fromUserId forKey:kMOReceivingInfoFromUserId];
- [aCoder encodeObject:_fromUserAvatar forKey:kMOReceivingInfoFromUserAvatar];
- [aCoder encodeDouble:_receivedNum forKey:kMOReceivingInfoReceivedNum];
- [aCoder encodeObject:_fromUserNickname forKey:kMOReceivingInfoFromUserNickname];
- [aCoder encodeDouble:_num forKey:kMOReceivingInfoNum];
- [aCoder encodeObject:_redEnvelopeId forKey:kMOReceivingInfoRedEnvelopeId];
- [aCoder encodeDouble:_lastReceiveSeq forKey:kMOReceivingInfoLastReceiveSeq];
-
- [aCoder encodeObject:_headdress forKey:kMOReceivingInfoHeaddress];
- [aCoder encodeBool:_headdressAnno forKey:kMOReceivingInfoHeaddressAnno];
-
- [aCoder encodeObject:_receivingUserList forKey:kMOReceivingInfoReceivingUserList];
- [aCoder encodeObject:_next forKey:kMOReceivingInfoNext];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOReceivingInfo *copy = [[MOReceivingInfo alloc] init];
-
-
-
- if (copy) {
- copy.receivingUserItems = [self.receivingUserItems copyWithZone:zone];
- copy.fromUserId = [self.fromUserId copyWithZone:zone];
- copy.fromUserAvatar = [self.fromUserAvatar copyWithZone:zone];
- copy.receivedNum = self.receivedNum;
- copy.fromUserNickname = [self.fromUserNickname copyWithZone:zone];
- copy.num = self.num;
- copy.redEnvelopeId = [self.redEnvelopeId copyWithZone:zone];
- copy.lastReceiveSeq = self.lastReceiveSeq;
-
- copy.headdress = [self.headdress copyWithZone:zone];
- copy.headdressAnno = self.headdressAnno;
-
- copy.receivingUserList = [self.receivingUserList copyWithZone:zone];
- copy.next = [self.next copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|