FLEXRuntimeKeyPath.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // FLEXRuntimeKeyPath.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/22/17.
  6. // Copyright © 2017 Tanner Bennett. All rights reserved.
  7. //
  8. #import "FLEXRuntimeKeyPath.h"
  9. @interface FLEXRuntimeKeyPath () {
  10. NSString *flex_description;
  11. }
  12. @end
  13. @implementation FLEXRuntimeKeyPath
  14. + (instancetype)empty {
  15. static FLEXRuntimeKeyPath *empty = nil;
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. FLEXSearchToken *any = FLEXSearchToken.any;
  19. empty = [self new];
  20. empty->_bundleKey = any;
  21. empty->flex_description = @"";
  22. });
  23. return empty;
  24. }
  25. + (instancetype)bundle:(FLEXSearchToken *)bundle
  26. class:(FLEXSearchToken *)cls
  27. method:(FLEXSearchToken *)method
  28. isInstance:(NSNumber *)instance
  29. string:(NSString *)keyPathString {
  30. FLEXRuntimeKeyPath *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->flex_description = keyPathString;
  40. return keyPath;
  41. }
  42. - (NSString *)description {
  43. return flex_description;
  44. }
  45. - (NSUInteger)hash {
  46. return flex_description.hash;
  47. }
  48. - (BOOL)isEqual:(id)object {
  49. if ([object isKindOfClass:[FLEXRuntimeKeyPath class]]) {
  50. FLEXRuntimeKeyPath *kp = object;
  51. return [flex_description isEqualToString:kp->flex_description];
  52. }
  53. return NO;
  54. }
  55. @end