NSString+RACKeyPathUtilities.m 866 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // NSString+RACKeyPathUtilities.m
  3. // ReactiveObjC
  4. //
  5. // Created by Uri Baghin on 05/05/2013.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import "NSString+RACKeyPathUtilities.h"
  9. @implementation NSString (RACKeyPathUtilities)
  10. - (NSArray *)rac_keyPathComponents {
  11. if (self.length == 0) {
  12. return nil;
  13. }
  14. return [self componentsSeparatedByString:@"."];
  15. }
  16. - (NSString *)rac_keyPathByDeletingLastKeyPathComponent {
  17. NSUInteger lastDotIndex = [self rangeOfString:@"." options:NSBackwardsSearch].location;
  18. if (lastDotIndex == NSNotFound) {
  19. return nil;
  20. }
  21. return [self substringToIndex:lastDotIndex];
  22. }
  23. - (NSString *)rac_keyPathByDeletingFirstKeyPathComponent {
  24. NSUInteger firstDotIndex = [self rangeOfString:@"."].location;
  25. if (firstDotIndex == NSNotFound) {
  26. return nil;
  27. }
  28. return [self substringFromIndex:firstDotIndex + 1];
  29. }
  30. @end