Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created October 28, 2015 18:40
Show Gist options
  • Save dhrrgn/40f9dccd761c421ebd75 to your computer and use it in GitHub Desktop.
Save dhrrgn/40f9dccd761c421ebd75 to your computer and use it in GitHub Desktop.
CSSearchableItemAttributeSet *attributeSet;
attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];
attributeSet.title = @"Some Title";
attributeSet.contentDescription = @"Some Destiption";
attributeSet.keywords = @[@"Some", @"Keyword"];
UIImage *image = [UIImage imageNamed:@"someOptionalImage.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"com.company"
domainIdentifier:@"spotlight.myDomain"
attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item]
completionHandler: ^(NSError * __nullable error) {
if (!error) {
NSLog(@"Search item indexed");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment