LookinTuple.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // LookinTuples.m
  3. // Lookin
  4. //
  5. // Created by Li Kai on 2019/8/14.
  6. // https://lookin.work
  7. //
  8. #import "LookinTuple.h"
  9. @implementation LookinTwoTuple
  10. - (void)encodeWithCoder:(NSCoder *)aCoder {
  11. [aCoder encodeObject:self.first forKey:@"first"];
  12. [aCoder encodeObject:self.second forKey:@"second"];
  13. }
  14. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  15. if (self = [super init]) {
  16. self.first = [aDecoder decodeObjectForKey:@"first"];
  17. self.second = [aDecoder decodeObjectForKey:@"second"];
  18. }
  19. return self;
  20. }
  21. + (BOOL)supportsSecureCoding {
  22. return YES;
  23. }
  24. - (NSUInteger)hash {
  25. return self.first.hash ^ self.second.hash;
  26. }
  27. - (BOOL)isEqual:(id)object {
  28. if (self == object) {
  29. return YES;
  30. }
  31. if (![object isKindOfClass:[LookinTwoTuple class]]) {
  32. return NO;
  33. }
  34. LookinTwoTuple *comparedObj = object;
  35. if ([self.first isEqual:comparedObj.first] && [self.second isEqual:comparedObj.second]) {
  36. return YES;
  37. }
  38. return NO;
  39. }
  40. @end
  41. @implementation LookinStringTwoTuple
  42. + (instancetype)tupleWithFirst:(NSString *)firstString second:(NSString *)secondString {
  43. LookinStringTwoTuple *tuple = [LookinStringTwoTuple new];
  44. tuple.first = firstString;
  45. tuple.second = secondString;
  46. return tuple;
  47. }
  48. #pragma mark - <NSCopying>
  49. - (id)copyWithZone:(NSZone *)zone {
  50. LookinStringTwoTuple *newTuple = [[LookinStringTwoTuple allocWithZone:zone] init];
  51. newTuple.first = self.first;
  52. newTuple.second = self.second;
  53. return newTuple;
  54. }
  55. #pragma mark - <NSCoding>
  56. - (void)encodeWithCoder:(NSCoder *)aCoder {
  57. [aCoder encodeObject:self.first forKey:@"first"];
  58. [aCoder encodeObject:self.second forKey:@"second"];
  59. }
  60. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  61. if (self = [super init]) {
  62. self.first = [aDecoder decodeObjectForKey:@"first"];
  63. self.second = [aDecoder decodeObjectForKey:@"second"];
  64. }
  65. return self;
  66. }
  67. + (BOOL)supportsSecureCoding {
  68. return YES;
  69. }
  70. @end