Class

CSSearchableIndex

The on-device index.

Declaration

@interface CSSearchableIndex : NSObject

Overview

The CSSearchableIndex class defines an object that represents the on-device index. In your app, you can designate user activities (that is, activities that can be represented by NSUserActivity) and app content as eligible for search. Using CSSearchableItem and CSSearchableItemAttributeSet APIs, you identify and provide information about activities and other items and then use CSSearchableIndex methods to manage the indexing of the items.

In some cases, it works well to batch updates to the index and save state information (up to 250 bytes) that helps you handle errors in the process. For example, you can use the client state information you pass in endIndexBatchWithClientState:completionHandler: to determine where indexing should resume in case of a crash or jetsam. (Note that state information is reset every time deleteAllSearchableItemsWithCompletionHandler: is called.) You can batch updates using indexSearchableItems:completionHandler: and deleteSearchableItemsWithIdentifiers:completionHandler:, but you can’t batch updates to the default index returned by defaultSearchableIndex.

In batch mode, the client takes responsibility for protecting the private CSSearchableIndex instance from concurrent access from multiple threads; concurrent calls to the index instance have undefined results. Although you can call beginIndexBatch again before the completion handler passed to endIndexBatchWithClientState:completionHandler: has been called, don’t call it before endIndexBatchWithClientState:completionHandler: has returned.

Topics

Determining Indexing Capability

+ isIndexingAvailable

Returns a Boolean value that indicates whether indexing is available on the current device.

Getting an Index

+ defaultSearchableIndex

Returns the default on-device index.

- initWithName:

Returns an on-device index with the specified name.

- initWithName:protectionClass:

Returns an on-device index with the specified name and data protection class.

Setting the Delegate

CSSearchableIndexDelegate

A protocol defining methods a delegate object or app extension uses to handle communication from the on-device index.

indexDelegate

The delegate object that can handle index-management tasks.

Managing Items in an Index

- deleteAllSearchableItemsWithCompletionHandler:

Deletes all searchable items from the index.

- deleteSearchableItemsWithDomainIdentifiers:completionHandler:

Removes from the index all searchable items associated with the specified domain.

- deleteSearchableItemsWithIdentifiers:completionHandler:

Removes from the index all items with the specified identifiers.

- indexSearchableItems:completionHandler:

Adds or updates items in the index.

Batching Index Updates

- beginIndexBatch

Begins a batch of updates to an index.

- endIndexBatchWithClientState:completionHandler:

Ends a batch of index updates and stores the specified state information.

- fetchLastClientStateWithCompletionHandler:

Gets the app’s most recently stored state information.

Relationships

Inherits From

See Also

Indexes

CSIndexExtensionRequestHandler

An interface that implements an index-maintenance app extension.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software