I want to search my eventList Array based on multiple parameters
like title,enddate etc…
I am using follwing code
when i use only one parameter titile like[cd] %@ it works perfectly
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *trimmed = [searchBar.text stringByTrimmingCharactersInSet:whitespace];
if([trimmed isEqualToString:@""]==NO)
{
// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title like[cd] %@",[NSString stringWithFormat:@"*%@*", searchBar.text]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title like[cd] %@ || enddate like[cd] %@ ",[NSString stringWithFormat:@"*%@*", searchBar.text],[NSString stringWithFormat:@"*%@*", searchBar.text]];
NSLog(@"Main Array:%@",arrMain);
eventsList =(NSMutableArray*) [arrMain filteredArrayUsingPredicate:predicate];
[eventsList retain];
NSLog(@"Search Result:%@",eventsList);
[eventTable reloadData];
}
i have tried with
NSPredicate predicate = [NSPredicate predicateWithFormat:@”(title like[cd] %@) OR (enddate like[cd] %@) “,[NSString stringWithFormat:@”%@“, searchBar.text],[NSString stringWithFormat:@”%@*”, searchBar.text]];
and it works also but not exact as i am searching for specific date it will not show
but if i write 2 or p or a it works for some result only…so i can say its not perfect
and
my enddate is string with format 2012-09-04 18:28:02
can any one help me with this….
Assemble an appropriate collection of individual predicates into NSCompoundPredicate
as in
You can stack up your predicates with orPredicateWithSubpredicates: and andPredicateWithSubpredicates: and NSCompoundPredicate being a NSPredicate itself can be compounded.
See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCompoundPredicate_Class/Reference/Reference.html