MOClickResultData.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // MOClickResultData.m
  3. //
  4. // Created by SuperCabbage on 2024/5/2
  5. // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOClickResultData.h"
  8. NSString *const kMOClickResultDataResult = @"result";
  9. NSString *const kMOClickResultDataStatus = @"status";
  10. NSString *const kMOClickResultDataDiamondSeed = @"diamondSeed";
  11. NSString *const kMOClickResultDataClickSeed = @"clickSeed";
  12. NSString *const kMOClickResultDataFullDiamond = @"fullDiamond";
  13. @interface MOClickResultData ()
  14. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  15. @end
  16. @implementation MOClickResultData
  17. @synthesize result = _result;
  18. @synthesize status = _status;
  19. @synthesize diamondSeed = _diamondSeed;
  20. @synthesize clickSeed = _clickSeed;
  21. @synthesize fullDiamond = _fullDiamond;
  22. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  23. return [[self alloc] initWithDictionary:dict];
  24. }
  25. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  26. self = [super init];
  27. // This check serves to make sure that a non-NSDictionary object
  28. // passed into the model class doesn't break the parsing.
  29. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  30. self.result = [[self objectOrNilForKey:kMOClickResultDataResult fromDictionary:dict] doubleValue];
  31. self.status = [[self objectOrNilForKey:kMOClickResultDataStatus fromDictionary:dict] doubleValue];
  32. self.diamondSeed = [[self objectOrNilForKey:kMOClickResultDataDiamondSeed fromDictionary:dict] longLongValue];
  33. self.clickSeed = [[self objectOrNilForKey:kMOClickResultDataClickSeed fromDictionary:dict] longLongValue];
  34. self.fullDiamond = [[self objectOrNilForKey:kMOClickResultDataFullDiamond fromDictionary:dict] boolValue];
  35. }
  36. return self;
  37. }
  38. - (NSDictionary *)dictionaryRepresentation {
  39. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  40. [mutableDict setValue:[NSNumber numberWithDouble:self.result] forKey:kMOClickResultDataResult];
  41. [mutableDict setValue:[NSNumber numberWithDouble:self.status] forKey:kMOClickResultDataStatus];
  42. [mutableDict setValue:[NSNumber numberWithLongLong:self.diamondSeed] forKey:kMOClickResultDataDiamondSeed];
  43. [mutableDict setValue:[NSNumber numberWithLongLong:self.clickSeed] forKey:kMOClickResultDataClickSeed];
  44. [mutableDict setValue:[NSNumber numberWithBool:self.fullDiamond] forKey:kMOClickResultDataFullDiamond];
  45. return [NSDictionary dictionaryWithDictionary:mutableDict];
  46. }
  47. - (NSString *)description {
  48. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  49. }
  50. #pragma mark - Helper Method
  51. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  52. id object = [dict objectForKey:aKey];
  53. return [object isEqual:[NSNull null]] ? nil : object;
  54. }
  55. #pragma mark - NSCoding Methods
  56. - (id)initWithCoder:(NSCoder *)aDecoder {
  57. self = [super init];
  58. self.result = [aDecoder decodeDoubleForKey:kMOClickResultDataResult];
  59. self.status = [aDecoder decodeDoubleForKey:kMOClickResultDataStatus];
  60. self.diamondSeed = [aDecoder decodeInt64ForKey:kMOClickResultDataDiamondSeed];
  61. self.clickSeed = [aDecoder decodeInt64ForKey:kMOClickResultDataClickSeed];
  62. self.fullDiamond = [aDecoder decodeBoolForKey:kMOClickResultDataFullDiamond];
  63. return self;
  64. }
  65. - (void)encodeWithCoder:(NSCoder *)aCoder
  66. {
  67. [aCoder encodeDouble:_result forKey:kMOClickResultDataResult];
  68. [aCoder encodeDouble:_status forKey:kMOClickResultDataStatus];
  69. [aCoder encodeInt64:_diamondSeed forKey:kMOClickResultDataDiamondSeed];
  70. [aCoder encodeInt64:_clickSeed forKey:kMOClickResultDataClickSeed];
  71. [aCoder encodeBool:_fullDiamond forKey:kMOClickResultDataFullDiamond];
  72. }
  73. - (id)copyWithZone:(NSZone *)zone {
  74. MOClickResultData *copy = [[MOClickResultData alloc] init];
  75. if (copy) {
  76. copy.result = self.result;
  77. copy.status = self.status;
  78. copy.diamondSeed = self.diamondSeed;
  79. copy.clickSeed = self.clickSeed;
  80. copy.fullDiamond = self.fullDiamond;
  81. }
  82. return copy;
  83. }
  84. @end