Unknown Error When Adding an CSSearchableitem to Core Spotlight (Macos)

Unknown Error when adding an CSSearchableItem to Core Spotlight (MacOS)

With macOS 10.13, SIP and the App Sandbox seem to have become a little more strict.
After a lot of digging to get this work, here's what I did, and should work for others reading this too:

  1. In Xcode, toggle the "App Sandbox" capability for your target in which your CoreSpotlight code runs. If this is in a framework, it needs to be the hosting application's target. This shouldn't be necessary for new projects (for details, see this bug report).
  2. Enable development signing for the application/binary which will run the CoreSpotlight code. In my case, it was the test host.

Update Spotlight Search Index when working with Core Data?

You want the indexing to be in sync with the deletion of your items. Hence look for these three methods implemented by CSSearchableIndex class to delete items when they are no longer required.

  1. deleteAllSearchableItemsWithCompletionHandler(_:)
  2. deleteSearchableItemsWithDomainIdentifiers(_:completionHandler:)
  3. deleteSearchableItemsWithIdentifiers(_:completionHandler:)

Like this example,

CSSearchableIndex.defaultSearchableIndex().deleteSearchableItemsWithDomainIdentifiers(["tv-shows"]) { (error) -> Void in    if error != nil {        print(error?.localizedDescription)    }    else {        // Items were deleted successfully    }}

Trying to use CoreSpotlight on OSX

The CoreSpotlight documentation suggests that API was added on macOS in High Sierra (10.13).

SDKs

iOS 9.0+

macOS 10.13+

I can confirm it works for me on macOS 10.13.

Since you are running 10.12, the API does not exist.



Related Topics



Leave a reply



Submit