forked from RestKit/RestKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRKSearchPredicate.m
More file actions
32 lines (25 loc) · 963 Bytes
/
Copy pathRKSearchPredicate.m
File metadata and controls
32 lines (25 loc) · 963 Bytes
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
//
// RKSearchPredicate.m
// RestKit
//
// Created by Blake Watters on 7/27/12.
// Copyright (c) 2012 RestKit. All rights reserved.
//
#import "RKSearchPredicate.h"
#import "RKStringTokenizer.h"
@implementation RKSearchPredicate
+ (NSPredicate *)searchPredicateWithText:(NSString *)searchText type:(NSCompoundPredicateType)type
{
return [[self alloc] initWithSearchText:searchText type:type];
}
- (instancetype)initWithSearchText:(NSString *)searchText type:(NSCompoundPredicateType)type
{
RKStringTokenizer *tokenizer = [RKStringTokenizer new];
NSSet *searchWords = [tokenizer tokenize:searchText];
NSMutableArray *subpredicates = [NSMutableArray arrayWithCapacity:[searchWords count]];
for (NSString *searchWord in searchWords) {
[subpredicates addObject:[NSPredicate predicateWithFormat:@"(ANY searchWords.word beginswith %@)", searchWord]];
}
return [super initWithType:type subpredicates:subpredicates];
}
@end