Skip to content

Instantly share code, notes, and snippets.

@rr-codes
Created August 13, 2021 02:33
Show Gist options
  • Save rr-codes/4e251539009dd1d64cd3e3bc5c13ae52 to your computer and use it in GitHub Desktop.
Save rr-codes/4e251539009dd1d64cd3e3bc5c13ae52 to your computer and use it in GitHub Desktop.
func index(countries: [Country]) {
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypePNG as String)
let items = countries.map { (country) -> CSSearchableItem in
attributeSet.title = country.name.common
attributeSet.contentDescription = "The flag of \(country.name.official)"
attributeSet.thumbnailData = UIImage(named: country.flagImageName)!.pngData()!
return CSSearchableItem(
uniqueIdentifier: country.id,
domainIdentifier: "com.richardrobinson.vexillum",
attributeSet: attributeSet
)
}
CSSearchableIndex.default().indexSearchableItems(items) { error in
if let error = error {
fatalError(error.localizedDescription)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment