Using Core Data Spotlight integration and NSUserActivity

The docs say that to avoid duplicating data in the Spotlight index, the relatedUniqueIdentifier for the NSUserActivity's contentAttributeSet should be set equal to the Core Spotlight searchable item's uniqueIdentifier.


"If you’re using both

NSUserActivity
and Core Spotlight APIs to index the same item, set this property [relatedUniqueIdentifier] in the activity to specify the unique identifier of the Core Spotlight item to which the activity is related, and to avoid displaying duplicate results in Spotlight."


But if Core Data is generating those searchable items automatically, using the NSCoreDataCoreSpotlightDelegate to just provide the attribute set, how can I get at the item's uniqueIdentifier? Is there a property I can set on the Spotlight attribute set that maps onto the uniqueIdentifier?

Looks like it's the object ID of the managed object - storing it as the NSUserActivity's relatedUniqueIdentifier removes the duplicate entries


activity.contentAttributeSet?.relatedUniqueIdentifier = object.objectID.uriRepresentation().absoluteString

I know this thread is quite old but I wanted to call your attention to the fact the NSCoreDataCoreSpotlightDelegate object has been updated with new features and functionality! In our session, "Showcase App Data in Spotlight", you'll:

  • 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.

We've released a [sample application](Showcase App Data in Spotlight) and updated our documentation to demonstrate how these new capabilities work.

For more information be sure to watch our session Showcase App Data in Spotlight on Wednesday.

Using Core Data Spotlight integration and NSUserActivity
 
 
Q