iOS Guides | Samples

CoreSpotlight Namespace

Allows applications to add data to the system search index.


Spotlight is the system search technology on iOS and OS X. CoreSpotlight allows developers to add data to the search index. An app about the periodic table, for instance, could index the various elements and bring up the relevant page after a search.

Adding data to Spotlight is done by adding CSSearchableItem objects to the CSSearchableIndex.DefaultSearchableIndex:

C# Example

//Create CSSearchableItems
var dataItems = searchIndexMap.Select (keyValuePair => {
    Guid guid = keyValuePair.Key;
    String data = keyValuePair.Value;
    var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
    attributeSet.Title = data + " Page";
    attributeSet.ContentDescription = "My app's data relating to " + data;
    attributeSet.TextContent = data;

    var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.CoreSpotlight0", attributeSet);
    return dataItem;
//Add items to system index
CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
    if (err != null) {
        Console.WriteLine (err);
    } else {
        Console.WriteLine ("Indexed items successfully");

When the application is launched via a Spotlight search for content, the system calls the UIApplicationDelegate.ContinueUserActivity method with the NSUserActivity.ActivityType set to ActionType:

C# Example

public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
    if (userActivity.ActivityType == CSSearchableItem.ActionType) {
        var uuid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier);
//... handle Spotlight search for identifier


CSCustomAttributeKeyA key that app developers can associate with metadata for an indexable item that can appear in user search results.
CSFileProtectionEnumerates file protection options in calls to CSSearchableIndex.FromName.
CSIndexErrorCodeEnumerates possible errors associated with using Core Spotlight and searching.
CSIndexErrorCodeExtensionsExtension methods for the CoreSpotlight.CSIndexErrorCode enumeration.
CSIndexExtensionRequestHandlerHandler for communication between the application and the index on the device. The app does not need to be running for this communication to occur.
CSLocalizedStringRepresents a string-like object that returns a locale-specific version of a string.
CSMailboxKeyRepresents keys that identify commonly used mailboxes.
CSPersonAn author or a recipient stored in a CSSearchableItemAttributeSet.
CSSearchableIndexA search index used by Spotlight.
CSSearchableIndex_CSOptionalBatchingExtensionExtension methods for T:CSSearchableIndex.
CSSearchableIndexDelegateDelegate object providing members that are called when reindexing the index.
CSSearchableIndexDelegate_ExtensionsExtension methods to the ICSSearchableIndexDelegate interface to support all the methods from the CSSearchableIndexDelegate protocol.
CSSearchableIndexFetchHandlerCompletion handler used in CSSearchableIndex.FetchLastClientState.
CSSearchableItemA uniquely identifiable, searchable object in a CSSearchableIndex.
CSSearchableItemAttributeSetHolds the actual content to be indexed for search.
CSSearchQuerySearches data that the developer has previously indexed with the Core Spotlight API.
CSSearchQueryErrorCodeEnumerates errors that can occur while running a Core Spotlight query with CSSearchQuery.Start.
CSSearchQueryErrorCodeExtensionsExtension methods for the CoreSpotlight.CSSearchQueryErrorCode enumeration.
ICSSearchableIndexDelegateInterface representing the required methods (if any) of the protocol CSSearchableIndexDelegate.