Skip to content

Instantly share code, notes, and snippets.

@DejanEnspyra
Last active February 27, 2018 18:31
Show Gist options
  • Save DejanEnspyra/823e0d48bb7e7dba326c79eeab2e3d5a to your computer and use it in GitHub Desktop.
Save DejanEnspyra/823e0d48bb7e7dba326c79eeab2e3d5a to your computer and use it in GitHub Desktop.
CoreSpotlight indexing
import CoreSpotlight
import MobileCoreServices
func indexSearchableItems(){
//let matches ...
var searchableItems = [CSSearchableItem]()
for match in matches {
let searchItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
searchItemAttributeSet.title = match.title
searchItemAttributeSet.contentDescription = match.content
searchItemAttributeSet.thumbnailData = match.image
let searchableItem = CSSearchableItem(uniqueIdentifier: match.id, domainIdentifier: "matches", attributeSet: searchItemAttributeSet)
searchableItems.append(searchableItem)
}
CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) -> Void in
if error != nil {
print(error?.localizedDescription ?? "Error")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment