Integrating Spotlight Search to iOS App | Part #1

Ömer Faruk Öztürk
iOS Dev
Published in
2 min readDec 5, 2017
image source: 9to5mac

Overview

Core Spotlight is a popular feature in iOS 9.0 that lets your app contents to appear on iOS Spotlight Search result, so that users can find content of your apps alongside other applications. By tapping the search results, users are redirected to your app, and you can show related content of related item.

Now, I want to explain some simple steps to integrate Spotlight Search function to your application.

To make our app content searchable we will use CSSearchableItem object with this initialization.

init(uniqueIdentifier: String?, 
domainIdentifier: String?,
attributeSet: CSSearchableItemAttributeSet)

uniqueIdentifier: An optipnal identifier that represents the current item. We will use it to pass additional parameter.

domainIdentifier: An optional identifier represents the domain of the item. We will use it to group items.

attributeSet: The set of attributes that contain metadata associated with the item in a CSSearchableItemAttributeSet object.

We will create an CSSearchableItemAttributeSet object with these properties.

title: The title of the item.

contentDescription: A description of the item’s content.

keywords: An array of keywords associated with the item.

thumbnailData: Image data that represents the thumbnail of the item.

source: developer.apple.com
  • This function given below creates an instance of CSSearchableItem and returns with given parameters. We can add additional values with parameters.
  • This functions adds specified set of CSSearchableItem list to spotlight item indexes.
  • Thats all. Now your contents can be listed in Spotlight search results.

One More

I have created a SpotlightManager file that contains all required functions that help you to integrate spotlight search to your app.

And you can find a sample project and sample usage of the manager here.

Thank you.

If you found this article useful please hit the “Clap” button below 👏

--

--