pdm: Thank you for your explanation. This helps me to wrap my head around the expectations as well. I want to make sure that I am thinking about the usage patterns as intended.
Let's assume I have a simple Notes app with two screens--a list view (ListVC) and a single note view (DetailVC). Let's say that the note has a Title and Body properties. I am assuming exlusive usage of NSUserActivity and no Core Spotlight integration.
Scenario 1:
* The user is looking at the list view
* The user taps on note and the DetailVC is pushed on to the nav stack with the activeNote set
* The DetailVC sets its userActivity with information appropriate for the activeNote
* The user leaves the app, searches in spotlight for the note ... and it appears ... great!
Scenario 2:
* The user goes back into the app, selects the same note and changes the title of the note
* The DetailVC updates the userActivity to reflect the new title
* The user leaves the app, searches in spotlight for the note ... and the same note appears twice under both the old and new title ... not so great.
Scenario 3:
* The user goes back into the app, and from the ListVC, decides to delete the note
* The user leaves the app, searches in spotlight for the note ... and the deleted note appears twice with both the old and new title ... really not so great.
This scenario, which feels rather typical to me ... leads me to the following conclusions, which I am hopeful that you can confirm:
1. If my app has user modifiable content, exclusive usage of NSUserActivity, without Core Spotlight is a bad idea.
As evidenced in the scenarios above, exclusive usage of NSUserActivity led spotlight to return inaccurate results in both an "Update" and "Delete" scenario.
"Update" failed because there is no unique identifer on an NSUserActivity. (From my tests, it appears that it is actually using the title property as the unique identifier, but it isn't allowing any updates to the item. The Spotlight search results are stuck with the original version of my note.)
"Delete" failed because there is no API to remove an NSUserActivity from the index, which of course would be dependent on a unique identifier.
(I thought that perhaps leveraging the relatedUniqueIdentifier might help, but as is documented, using this alone, without Core Spotlight leads to your item not being indexed.)
2. Exlcusive usage of NSUserActivity, only makes sense in an app with read-only, static content.
Given the scenarios above, I cannot think of any other way that using NSUserActivity exclusively makes sense with respect to Search. (Assuming the scenarios above concern you of course.)
3. When using Core Spotlight and NSUserActivity together, the item must be indexed by Core Spotlight before it can be indexed by NSUserActivity.
This is due to the issue around the relatedUniqueIdentifier only working if the item already exists in Core Spotlight.
Based on potential timing of indexing things in Core Spotlight, if using batching or working on a background thread, or perhaps only indexing the "top items" in Core Spotlight and not all 100k that might exist in your app, this would lead me to the following conclusion about a best practice ... which concerns me.
4. When using NSUserActivity and Core Spotlight, immediately before creating the NSUserActivity, synchronously add an entry to Core Spotlight.
For obvious reasons, this last assertion concerns me, as it sounds a bit like a hack, yet, it seems like the only way to predictably ensure that your NSUserActivity will make it into the search index.
Thank you for taking the time to consider these assertions. As mentioned, I am really trying to wrap my head around the "best practices" and the "intentions" when working with these APIs. Any and all pointers are greatly appreciated.
--Chris