LookinAttributesGroup.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. //
  3. // LookinAttributesGroup.m
  4. // Lookin
  5. //
  6. // Created by Li Kai on 2018/11/19.
  7. // https://lookin.work
  8. //
  9. #import "LookinAttributesGroup.h"
  10. #import "LookinAttribute.h"
  11. #import "LookinAttributesSection.h"
  12. #import "LookinDashboardBlueprint.h"
  13. #import "NSArray+Lookin.h"
  14. @implementation LookinAttributesGroup
  15. #pragma mark - <NSCopying>
  16. - (id)copyWithZone:(NSZone *)zone {
  17. LookinAttributesGroup *newGroup = [[LookinAttributesGroup allocWithZone:zone] init];
  18. newGroup.userCustomTitle = self.userCustomTitle;
  19. newGroup.identifier = self.identifier;
  20. newGroup.attrSections = [self.attrSections lookin_map:^id(NSUInteger idx, LookinAttributesSection *value) {
  21. return value.copy;
  22. }];
  23. return newGroup;
  24. }
  25. #pragma mark - <NSCoding>
  26. - (void)encodeWithCoder:(NSCoder *)aCoder {
  27. [aCoder encodeObject:self.userCustomTitle forKey:@"userCustomTitle"];
  28. [aCoder encodeObject:self.identifier forKey:@"identifier"];
  29. [aCoder encodeObject:self.attrSections forKey:@"attrSections"];
  30. }
  31. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  32. if (self = [super init]) {
  33. self.userCustomTitle = [aDecoder decodeObjectForKey:@"userCustomTitle"];
  34. self.identifier = [aDecoder decodeObjectForKey:@"identifier"];
  35. self.attrSections = [aDecoder decodeObjectForKey:@"attrSections"];
  36. }
  37. return self;
  38. }
  39. - (NSUInteger)hash {
  40. return self.uniqueKey.hash;
  41. }
  42. - (BOOL)isEqual:(id)object {
  43. if (self == object) {
  44. return YES;
  45. }
  46. if (![object isKindOfClass:[LookinAttributesGroup class]]) {
  47. return NO;
  48. }
  49. LookinAttributesGroup *targetObject = object;
  50. if (![self.identifier isEqualToString:targetObject.identifier]) {
  51. return false;
  52. }
  53. if ([self.identifier isEqualToString:LookinAttrGroup_UserCustom]) {
  54. BOOL ret = [self.userCustomTitle isEqualToString:targetObject.userCustomTitle];
  55. return ret;
  56. } else {
  57. return true;
  58. }
  59. }
  60. + (BOOL)supportsSecureCoding {
  61. return YES;
  62. }
  63. - (NSString *)uniqueKey {
  64. if ([self.identifier isEqualToString:LookinAttrGroup_UserCustom]) {
  65. return self.userCustomTitle;
  66. } else {
  67. return self.identifier;
  68. }
  69. }
  70. - (BOOL)isUserCustom {
  71. return [self.identifier isEqualToString:LookinAttrSec_UserCustom];
  72. }
  73. @end
  74. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */