Class

CSSearchableIndex

The on-device index.

Declaration

class 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 endBatch(withClientState:completionHandler:) to determine where indexing should resume in case of a crash or jetsam. (Note that state information is reset every time deleteAllSearchableItems(completionHandler:) is called.) You can batch updates using indexSearchableItems(_:completionHandler:) and deleteSearchableItems(withIdentifiers:completionHandler:), but you can’t batch updates to the default index returned by default().

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 beginBatch() again before the completion handler passed to endBatch(withClientState:completionHandler:) has been called, don’t call it before endBatch(withClientState:completionHandler:) has returned.

Topics

Determining Indexing Capability

class func isIndexingAvailable() -> Bool

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

Getting an Index

class func `default`() -> Self

Returns the default on-device index.

init(name: String)

Returns an on-device index with the specified name.

init(name: String, protectionClass: FileProtectionType?)

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

Setting the Delegate

protocol CSSearchableIndexDelegate

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

var indexDelegate: CSSearchableIndexDelegate?

The delegate object that can handle index-management tasks.

Managing Items in an Index

Batching Index Updates

func beginBatch()

Begins a batch of updates to an index.

func endBatch(withClientState: Data, completionHandler: ((Error?) -> Void)?)

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

func fetchLastClientState(completionHandler: (Data?, Error?) -> Void)

Gets the app’s most recently stored state information.

Relationships

Inherits From

Conforms To

See Also

Indexes

class CSIndexExtensionRequestHandler

An interface that implements an index-maintenance app extension.