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