Skip to content

Instantly share code, notes, and snippets.

@ArchieGoodwin
Created August 16, 2015 12:30
Show Gist options
  • Save ArchieGoodwin/7d7b76e10c952d1ada05 to your computer and use it in GitHub Desktop.
Save ArchieGoodwin/7d7b76e10c952d1ada05 to your computer and use it in GitHub Desktop.
CoreSpotlight search index addition in swift
func spotLighIndexingForContact(contact: MainContact) -> AnyObject
{
if #available(iOS 9, *) {
let attributeSet : CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
let name : String = contact.firstname + " " + contact.lastname
attributeSet.title = name
attributeSet.contentDescription = "Main Contact"
let imgData = UIImagePNGRepresentation(UIImage(named: "3dotsHome")!)
attributeSet.thumbnailData = imgData
var item: CSSearchableItem
let identifier = contact.guid
item = CSSearchableItem(uniqueIdentifier: identifier, domainIdentifier: "co.getmain.search", attributeSet: attributeSet)
return item
}
return ""
}
func spotLighIndexingForContactAndPhoto(contact: MainContact, photo: UIImage) -> AnyObject
{
if #available(iOS 9, *) {
let attributeSet : CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
let name : String = contact.firstname + " " + contact.lastname
attributeSet.title = name
attributeSet.contentDescription = "Tap to see full contact info"
let imgData = UIImageJPEGRepresentation(photo, 0.7)
attributeSet.thumbnailData = imgData
var item: CSSearchableItem
let identifier = contact.guid
item = CSSearchableItem(uniqueIdentifier: identifier, domainIdentifier: "co.getmain.search", attributeSet: attributeSet)
return item
}
return ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment