How to create an NSPredicate that filters all characters in a given range, including digits / digits?


I want to implement full text search and what I do is this:

NSString* start = @"a";
NSString* stop = [start stringByAppendingString:@"zzz"];
NSArray* range = [NSArray arrayWithObjects:[NSExpression expressionForConstantValue:start],[NSExpression expressionForConstantValue:stop],nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY keyword.word BETWEEN %@",range];

Start is variable and changes depending what I type (i.e. if I type 'cool' it means start= @"cool" and stop will be @"coolzzz").

Now this works great until my input is a digit or number and the NSPredicate doesn't return any results even though there are.

For example in my data I have entries of shape entry_name 1, entry_name 2. If I input entry_name I get all results but as soon as I input entry_name 1 I get no results.

After testing I've seen that if I just enter 1 I get no results so the NSPredicate doesn't work.

How can I write an NSPredicate which filters all the characters including digits?

You don't need to create a range for the BETWEEN operator, a simple array is enough:

NSString* start = @"a";
NSString* stop = [start stringByAppendingString:@"zzz"];
NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@",
                                     [NSArray arrayWithObjects:start, stop, nil]];

See also Predicate Programming Guide