Contents

CSSearchableIndex

An on-device index for your app’s searchable content.

Declaration

class CSSearchableIndex

Mentioned in

Overview

A CSSearchableIndex object manages an on-device index for your app’s searchable content. To make your app’s content searchable, package it in one or more CSSearchableItem objects and add them to the index. You can create as many searchable indexes as you need to manage your content, and you can apply different levels of encryption to protect the content in each index. When you execute a query, Core Spotlight searches your app’s indexes for the requested information and returns the results to your code.

Put your content into a custom CSSearchableIndex that you create. Custom indexes support batch operations and additional levels of data protection. Place sensitive personal information in protected indexes to encrypt that content, and prevent its disclosure without proper authorization from the owner of the device. Although you can put content into the default index, you can’t encrypt the content in that index or perform batch operations to add content to it.

When adding large amounts of data to the index, consider adding it in batches to minimize risk. Batch-based updates make it easier to handle errors that might occur during the indexing process. For each batch, you provide client-state information to identify the current batch. If your app or extension crashes while a batch operation is in progress, you can use that state information to determine where to start indexing again later.

Modify custom CSSearchableIndex objects only on one thread or task at a time. It’s a programming error to access a custom index from multiple threads simultaneously. When performing batch updates on an index, start each new batch operation only after calling the endBatch(withClientState:completionHandler:) or endIndexBatch(expectedClientState:newClientState:completionHandler:) method of the previous batch operation.

Topics

Creating an index

Determining if indexing is available

Responding to index-related changes

Managing items in an index

Indexing app entities

Batching index updates

Handling drag and drop content

See Also

Indexes