How to implement core spotlight indexing in core data?

690 views Asked by At

I am having issue with making Core Data searchable using Core Spotlight in iOS. I checked Index For Spotlight for some attributes like name, date modified for a. I subclassed NSCoreDataCoreSpotlightDelegate and called setOption(spotlightDelegate, forKey: NSCoreDataCoreSpotlightExporter) on persistent container's store description before loading persistent stores. In the logs, CoreData prints that it has successfully initialised by NSCoreDataCoreSpotlightDelegate subclass, but I am not able to see any record in spotlight.

Do I have to set Spotlight Display Name for entity also?

1

There are 1 answers

1
davidstites On

I know this thread is old but I would recommend you check out https://developer.apple.com/wwdc21/10098. This session is all about the updates to the NSCoreDataCoreSpotlightDelegate in iOS 15.

  • Discover how Core Data can surface data from your app in Spotlight with as little as two lines of code.
  • Learn how to make that data discoverable in Spotlight search and to customize how it is presented to people on device.
  • See how to implement full-text search within your app, driven completely with the data indexed by Spotlight.

There is an associated sample application to demonstrate how these new capabilities work.