MOSignPrizes.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // MOSignPrizes.m
  3. //
  4. // Created by SuperCabbage on 2024/5/31
  5. // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOSignPrizes.h"
  8. NSString *const kMOSignPrizesAmount = @"amount";
  9. NSString *const kMOSignPrizesIcon = @"icon";
  10. NSString *const kMOSignPrizesType = @"type";
  11. NSString *const kMOSignPrizesName = @"name";
  12. NSString *const kMOSignPrizesTag = @"tag";
  13. @interface MOSignPrizes ()
  14. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  15. @end
  16. @implementation MOSignPrizes
  17. @synthesize amount = _amount;
  18. @synthesize icon = _icon;
  19. @synthesize type = _type;
  20. @synthesize name = _name;
  21. @synthesize tag = _tag;
  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.amount = [[self objectOrNilForKey:kMOSignPrizesAmount fromDictionary:dict] doubleValue];
  31. self.icon = [self objectOrNilForKey:kMOSignPrizesIcon fromDictionary:dict];
  32. self.type = [[self objectOrNilForKey:kMOSignPrizesType fromDictionary:dict] doubleValue];
  33. self.name = [self objectOrNilForKey:kMOSignPrizesName fromDictionary:dict];
  34. self.tag = [[self objectOrNilForKey:kMOSignPrizesTag fromDictionary:dict] doubleValue];
  35. }
  36. return self;
  37. }
  38. - (NSDictionary *)dictionaryRepresentation {
  39. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  40. [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kMOSignPrizesAmount];
  41. [mutableDict setValue:self.icon forKey:kMOSignPrizesIcon];
  42. [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kMOSignPrizesType];
  43. [mutableDict setValue:self.name forKey:kMOSignPrizesName];
  44. [mutableDict setValue:[NSNumber numberWithDouble:self.tag] forKey:kMOSignPrizesTag];
  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.amount = [aDecoder decodeDoubleForKey:kMOSignPrizesAmount];
  59. self.icon = [aDecoder decodeObjectForKey:kMOSignPrizesIcon];
  60. self.type = [aDecoder decodeDoubleForKey:kMOSignPrizesType];
  61. self.name = [aDecoder decodeObjectForKey:kMOSignPrizesName];
  62. self.tag = [aDecoder decodeDoubleForKey:kMOSignPrizesTag];
  63. return self;
  64. }
  65. - (void)encodeWithCoder:(NSCoder *)aCoder
  66. {
  67. [aCoder encodeDouble:_amount forKey:kMOSignPrizesAmount];
  68. [aCoder encodeObject:_icon forKey:kMOSignPrizesIcon];
  69. [aCoder encodeDouble:_type forKey:kMOSignPrizesType];
  70. [aCoder encodeObject:_name forKey:kMOSignPrizesName];
  71. [aCoder encodeDouble:_tag forKey:kMOSignPrizesTag];
  72. }
  73. - (id)copyWithZone:(NSZone *)zone {
  74. MOSignPrizes *copy = [[MOSignPrizes alloc] init];
  75. if (copy) {
  76. copy.amount = self.amount;
  77. copy.icon = [self.icon copyWithZone:zone];
  78. copy.type = self.type;
  79. copy.name = [self.name copyWithZone:zone];
  80. copy.tag = self.tag;
  81. }
  82. return copy;
  83. }
  84. @end