Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
- (void)indexAirportData
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
for (ALAirport* airport in self.airports)
{
// Create the attribute set
CSSearchableItemAttributeSet* attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeItem];
attributeSet.displayName = airport.airportName;
attributeSet.latitude = @(airport.coordinate.latitude);
attributeSet.longitude = @(airport.coordinate.longitude);
attributeSet.thumbnailData = UIImagePNGRepresentation([UIImage imageNamed:@"AppIcon"]);
// Create the searchable item
CSSearchableItem* item = [[CSSearchableItem alloc] initWithUniqueIdentifier:airport.airportIdentifier
domainIdentifier:@"airports"
attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item]
completionHandler:^(NSError * _Nullable error) {
NSLog(@"Indexed: %@", airport.airportName);
}];
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment