I am trying to using CoreSpotlight
API in application , I have plist file which has a several items on it for example animals' name . So I need to set title
string equal to on of those object , for example if users search Lion , the line name and for example its features appears on the spotlight . Here is my code :
- (void)setupCoreSpotlightSearch
{
CSSearchableItemAttributeSet *attibuteSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(__bridge NSString *)kUTTypeImage];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"animals" withExtension:@"plist"];
NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];
NSString *getNames = [NSString stringWithFormat:@"%@",playDictionariesArray];
NSLog(@"%@",getNames) ;
attibuteSet.title =getNames;
attibuteSet.contentDescription = @"blah blah ";
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"app name"
domainIdentifier:@"com.compont.appname"
attributeSet:attibuteSet];
if (item) {
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Search item indexed");
}
}];
}
}
The problem is getNames
returns all names !!! how can I filter it when is user is searching an specific word from animals.plist
Thanks .
attibuteSet.title
?? This is my main issue and must have a value – Chock