MOGuildBase.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // MOGuildBase.m
  3. //
  4. // Created by SuperCabbage on 2023/10/25
  5. // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOGuildBase.h"
  8. NSString *const kMOGuildBaseAnchor = @"anchor";
  9. NSString *const kMOGuildBaseId = @"id";
  10. NSString *const kMOGuildBaseCountry = @"country";
  11. NSString *const kMOGuildBaseName = @"name";
  12. NSString *const kMOGuildBaseLogo = @"logo";
  13. NSString *const kMOGuildBaseNo = @"no";
  14. @interface MOGuildBase ()
  15. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  16. @end
  17. @implementation MOGuildBase
  18. @synthesize anchor = _anchor;
  19. @synthesize id = _id;
  20. @synthesize country = _country;
  21. @synthesize name = _name;
  22. @synthesize logo = _logo;
  23. @synthesize no = _no;
  24. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  25. return [[self alloc] initWithDictionary:dict];
  26. }
  27. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  28. self = [super init];
  29. // This check serves to make sure that a non-NSDictionary object
  30. // passed into the model class doesn't break the parsing.
  31. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  32. self.anchor = [[self objectOrNilForKey:kMOGuildBaseAnchor fromDictionary:dict] doubleValue];
  33. self.id = [self objectOrNilForKey:kMOGuildBaseId fromDictionary:dict];
  34. self.country = [self objectOrNilForKey:kMOGuildBaseCountry fromDictionary:dict];
  35. self.name = [self objectOrNilForKey:kMOGuildBaseName fromDictionary:dict];
  36. self.logo = [self objectOrNilForKey:kMOGuildBaseLogo fromDictionary:dict];
  37. self.no = [self objectOrNilForKey:kMOGuildBaseNo fromDictionary:dict];
  38. }
  39. return self;
  40. }
  41. - (NSDictionary *)dictionaryRepresentation {
  42. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  43. [mutableDict setValue:[NSNumber numberWithDouble:self.anchor] forKey:kMOGuildBaseAnchor];
  44. [mutableDict setValue:self.id forKey:kMOGuildBaseId];
  45. [mutableDict setValue:self.country forKey:kMOGuildBaseCountry];
  46. [mutableDict setValue:self.name forKey:kMOGuildBaseName];
  47. [mutableDict setValue:self.logo forKey:kMOGuildBaseLogo];
  48. [mutableDict setValue:self.no forKey:kMOGuildBaseNo];
  49. return [NSDictionary dictionaryWithDictionary:mutableDict];
  50. }
  51. - (NSString *)description {
  52. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  53. }
  54. #pragma mark - Helper Method
  55. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  56. id object = [dict objectForKey:aKey];
  57. return [object isEqual:[NSNull null]] ? nil : object;
  58. }
  59. #pragma mark - NSCoding Methods
  60. - (id)initWithCoder:(NSCoder *)aDecoder {
  61. self = [super init];
  62. self.anchor = [aDecoder decodeDoubleForKey:kMOGuildBaseAnchor];
  63. self.id = [aDecoder decodeObjectForKey:kMOGuildBaseId];
  64. self.country = [aDecoder decodeObjectForKey:kMOGuildBaseCountry];
  65. self.name = [aDecoder decodeObjectForKey:kMOGuildBaseName];
  66. self.logo = [aDecoder decodeObjectForKey:kMOGuildBaseLogo];
  67. self.no = [aDecoder decodeObjectForKey:kMOGuildBaseNo];
  68. return self;
  69. }
  70. - (void)encodeWithCoder:(NSCoder *)aCoder
  71. {
  72. [aCoder encodeDouble:_anchor forKey:kMOGuildBaseAnchor];
  73. [aCoder encodeObject:_id forKey:kMOGuildBaseId];
  74. [aCoder encodeObject:_country forKey:kMOGuildBaseCountry];
  75. [aCoder encodeObject:_name forKey:kMOGuildBaseName];
  76. [aCoder encodeObject:_logo forKey:kMOGuildBaseLogo];
  77. [aCoder encodeObject:_no forKey:kMOGuildBaseNo];
  78. }
  79. - (id)copyWithZone:(NSZone *)zone {
  80. MOGuildBase *copy = [[MOGuildBase alloc] init];
  81. if (copy) {
  82. copy.anchor = self.anchor;
  83. copy.id = [self.id copyWithZone:zone];
  84. copy.country = [self.country copyWithZone:zone];
  85. copy.name = [self.name copyWithZone:zone];
  86. copy.logo = [self.logo copyWithZone:zone];
  87. copy.no = [self.no copyWithZone:zone];
  88. }
  89. return copy;
  90. }
  91. @end