TBKeyPath.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // TBKeyPath.m
  3. // TBTweakViewController
  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)bundle:(TBToken *)bundle
  15. class:(TBToken *)cls
  16. method:(TBToken *)method
  17. isInstance:(NSNumber *)instance
  18. string:(NSString *)keyPathString {
  19. TBKeyPath *keyPath = [self new];
  20. keyPath->_bundleKey = bundle;
  21. keyPath->_classKey = cls;
  22. keyPath->_methodKey = method;
  23. keyPath->_instanceMethods = instance;
  24. // Remove irrelevant trailing '*' for equality purposes
  25. if ([keyPathString hasSuffix:@"*"]) {
  26. keyPathString = [keyPathString substringToIndex:keyPathString.length];
  27. }
  28. keyPath->tb_description = keyPathString;
  29. return keyPath;
  30. }
  31. - (NSString *)description {
  32. return tb_description;
  33. }
  34. - (NSUInteger)hash {
  35. return tb_description.hash;
  36. }
  37. - (BOOL)isEqual:(id)object {
  38. if ([object isKindOfClass:[TBKeyPath class]]) {
  39. TBKeyPath *kp = object;
  40. return [tb_description isEqualToString:kp->tb_description];
  41. }
  42. return NO;
  43. }
  44. @end