MOFanTaskInfo.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // MOFanTaskInfo.m
  3. //
  4. // Created by SuperCabbage on 2024/5/30
  5. // Copyright (c) 2024 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOFanTaskInfo.h"
  8. NSString *const kMOFanTaskInfoTitle = @"title";
  9. NSString *const kMOFanTaskInfoIcon = @"icon";
  10. NSString *const kMOFanTaskInfoIntimacy = @"intimacy";
  11. NSString *const kMOFanTaskInfoCompleteNum = @"completeNum";
  12. @interface MOFanTaskInfo ()
  13. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  14. @end
  15. @implementation MOFanTaskInfo
  16. @synthesize title = _title;
  17. @synthesize icon = _icon;
  18. @synthesize intimacy = _intimacy;
  19. @synthesize completeNum = _completeNum;
  20. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  21. return [[self alloc] initWithDictionary:dict];
  22. }
  23. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  24. self = [super init];
  25. // This check serves to make sure that a non-NSDictionary object
  26. // passed into the model class doesn't break the parsing.
  27. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  28. self.title = [self objectOrNilForKey:kMOFanTaskInfoTitle fromDictionary:dict];
  29. self.icon = [self objectOrNilForKey:kMOFanTaskInfoIcon fromDictionary:dict];
  30. self.intimacy = [[self objectOrNilForKey:kMOFanTaskInfoIntimacy fromDictionary:dict] doubleValue];
  31. self.completeNum = [[self objectOrNilForKey:kMOFanTaskInfoCompleteNum fromDictionary:dict] doubleValue];
  32. }
  33. return self;
  34. }
  35. - (NSDictionary *)dictionaryRepresentation {
  36. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  37. [mutableDict setValue:self.title forKey:kMOFanTaskInfoTitle];
  38. [mutableDict setValue:self.icon forKey:kMOFanTaskInfoIcon];
  39. [mutableDict setValue:[NSNumber numberWithDouble:self.intimacy] forKey:kMOFanTaskInfoIntimacy];
  40. [mutableDict setValue:[NSNumber numberWithDouble:self.completeNum] forKey:kMOFanTaskInfoCompleteNum];
  41. return [NSDictionary dictionaryWithDictionary:mutableDict];
  42. }
  43. - (NSString *)description {
  44. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  45. }
  46. #pragma mark - Helper Method
  47. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  48. id object = [dict objectForKey:aKey];
  49. return [object isEqual:[NSNull null]] ? nil : object;
  50. }
  51. #pragma mark - NSCoding Methods
  52. - (id)initWithCoder:(NSCoder *)aDecoder {
  53. self = [super init];
  54. self.title = [aDecoder decodeObjectForKey:kMOFanTaskInfoTitle];
  55. self.icon = [aDecoder decodeObjectForKey:kMOFanTaskInfoIcon];
  56. self.intimacy = [aDecoder decodeDoubleForKey:kMOFanTaskInfoIntimacy];
  57. self.completeNum = [aDecoder decodeDoubleForKey:kMOFanTaskInfoCompleteNum];
  58. return self;
  59. }
  60. - (void)encodeWithCoder:(NSCoder *)aCoder
  61. {
  62. [aCoder encodeObject:_title forKey:kMOFanTaskInfoTitle];
  63. [aCoder encodeObject:_icon forKey:kMOFanTaskInfoIcon];
  64. [aCoder encodeDouble:_intimacy forKey:kMOFanTaskInfoIntimacy];
  65. [aCoder encodeDouble:_completeNum forKey:kMOFanTaskInfoCompleteNum];
  66. }
  67. - (id)copyWithZone:(NSZone *)zone {
  68. MOFanTaskInfo *copy = [[MOFanTaskInfo alloc] init];
  69. if (copy) {
  70. copy.title = [self.title copyWithZone:zone];
  71. copy.icon = [self.icon copyWithZone:zone];
  72. copy.intimacy = self.intimacy;
  73. copy.completeNum = self.completeNum;
  74. }
  75. return copy;
  76. }
  77. @end