Last active
February 27, 2018 18:31
-
-
Save DejanEnspyra/823e0d48bb7e7dba326c79eeab2e3d5a to your computer and use it in GitHub Desktop.
CoreSpotlight indexing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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