I have a Person Object which has two NSString properties; firstName and lastName.
I’m currently using an NSPredicate like so:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName contains[cd] %@) OR (lastName contains[cd] %@)", searchText, searchText];
So, for example, say I’m searching for the name "John Smith". In my search bar if I type "Joh", then John Smith will appear as an option. This is good and fine, but if I type in "John Sm" it will go blank.
How can I join firstName and lastName in the predicate so if I was searching for "John Sm" then John Smith would still appear as an option.
I hope this makes sense. Thanks.
EDIT:
To add a bit more clarification, I’m using the SearchDisplayController delegate method:
-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope;
and I’m using the predicate like so:
newArray = [personObjectArray filteredArrayUsingPredicate:predicate];
Try this,
Output:
Here text represents the searched text. The advantage with the above is, even if you pass
text = @"Smi Joh";ortext = @"John ";ortext = @" smi";ortext = @"joh smi ";, it will still show the above output.