TBKeyPath.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // FLEXKeyPath.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/22/17.
  6. // Copyright © 2017 Tanner Bennett. All rights reserved.
  7. //
  8. #import "TBKeyPath.h"
  9. @interface TBKeyPath () {
  10. NSString *tb_description;
  11. }
  12. @end
  13. @implementation TBKeyPath
  14. + (instancetype)empty {
  15. static TBKeyPath *empty = nil;
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. TBToken *any = [TBToken any];
  19. empty = [self new];
  20. empty->_bundleKey = any;
  21. empty->tb_description = @"";
  22. });
  23. return empty;
  24. }
  25. + (instancetype)bundle:(TBToken *)bundle
  26. class:(TBToken *)cls
  27. method:(TBToken *)method
  28. isInstance:(NSNumber *)instance
  29. string:(NSString *)keyPathString {
  30. TBKeyPath *keyPath = [self new];
  31. keyPath->_bundleKey = bundle;
  32. keyPath->_classKey = cls;
  33. keyPath->_methodKey = method;
  34. keyPath->_instanceMethods = instance;
  35. // Remove irrelevant trailing '*' for equality purposes
  36. if ([keyPathString hasSuffix:@"*"]) {
  37. keyPathString = [keyPathString substringToIndex:keyPathString.length];
  38. }
  39. keyPath->tb_description = keyPathString;
  40. return keyPath;
  41. }
  42. - (NSString *)description {
  43. return tb_description;
  44. }
  45. - (NSUInteger)hash {
  46. return tb_description.hash;
  47. }
  48. - (BOOL)isEqual:(id)object {
  49. if ([object isKindOfClass:[TBKeyPath class]]) {
  50. TBKeyPath *kp = object;
  51. return [tb_description isEqualToString:kp->tb_description];
  52. }
  53. return NO;
  54. }
  55. @end