How to filter data on the entry of characters only from the first letters of each word? To the search string "VI"

found such names: 1 " VI Ktor Bondarev", 2 "Alexander VI Slukh"

and did not find such: 3 "Peter Artyom VI h", 4 "e VI l Carlo VI h"

Now it works like this, but you need to discard the 3 and 4 options:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", searchText]; NSArray *authors = [DAKAuthor MR_findAllWithPredicate:predicate]; 

2 answers 2

To find the first letters of each word, put a space before searchText:

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", [NSString stringWithFormat:@" %@", searchText]]; NSArray *authors = [DAKAuthor MR_findAllWithPredicate:predicate]; 

    For this task, it is best to combine BEGINSWITH and CONTAINS

     NSString* searchTextWithSpase = [NSString stringWithFormat:@" %@", searchText]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@ OR name BEGINSWITH[c] %@" , searchTextWithSpase, searchText]; NSArray *authors = [DAKAuthor MR_findAllWithPredicate:predicate];