Created
February 9, 2018 20:19
-
-
Save MathVasc/17881b7fba53d8fe10ac6d5276c81a76 to your computer and use it in GitHub Desktop.
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
public static func setSpotLightIndexes(){ | |
let items = DAOItem.sharedInstance.fetchItems() | |
var searchableItems = [CSSearchableItem]() | |
// deletando todos os itens | |
CSSearchableIndex.default().deleteAllSearchableItems { (error) in | |
guard error == nil else { | |
print(error!.localizedDescription) | |
return | |
} | |
} | |
// criando todos os itens | |
for item in items { | |
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String) | |
attributeSet.keywords = ["Groceries", "Grocery", "List", "Ericow"] | |
attributeSet.title = item.name | |
attributeSet.contentDescription = item.isDone ? "\(item.name!) was bought" : "\(item.name!) wasn't bought" | |
attributeSet.thumbnailData = item.isDone ? UIImagePNGRepresentation(UIImage(named: "Check")!) : UIImagePNGRepresentation(UIImage(named:"Uncheck")!) | |
searchableItems.append(CSSearchableItem(uniqueIdentifier: item.name!, domainIdentifier: nil, attributeSet: attributeSet)) | |
} | |
// adicionando todos os itens | |
CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) in | |
guard error == nil else { | |
print(error!.localizedDescription) | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment