LookinTuple.m 2.0 KB

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