I have a searchDisplayController
which works perfectly when searching for English and Arabic words using a method as follows:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope
{
NSString *query = self.searchDisplayController.searchBar.text;
if (query && query.length) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ClientName contains[cd] %@", query];
[searchResultController_.fetchRequest setPredicate:predicate];
}
NSError *error = nil;
if (![[self searchResultController] performFetch:&error]) {
// Handle error
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
}
However, this works fine if the iphone language is English, but if I change the iPhone language to Arabic (global settings) and tried to search in Arabic or English words the searchResultsController
will not display results, why ?
p.s. when I put a static Arabic word in query like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ClientName contains[cd] %@", @"تجريب"];
the searchDisplayController
will display the correct result of the arabic word تجريب
EDIT: I've tried to build the predicate in code like this :
NSExpression *clientNameEx=[NSExpression expressionForKeyPath:@"ClientName"];
NSExpression *aClientEx=[NSExpression expressionForConstantValue:query];
NSPredicate *predicate=[NSComparisonPredicate predicateWithLeftExpression:clientNameEx
rightExpression:aClientEx
modifier:NSDirectPredicateModifier
type:NSContainsPredicateOperatorType
options:0];
but to no avail ...