Created
August 16, 2015 12:30
-
-
Save ArchieGoodwin/7d7b76e10c952d1ada05 to your computer and use it in GitHub Desktop.
CoreSpotlight search index addition in swift
This file contains 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
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