You mentioned that when object is tapped, it gets the id from AppEntity object, use it to search in EntityQuery.entities(for:), and get an AppEtity back, it seems to be a redundant step if we already had the AppEntity object in the beginning?
Since the results are displayed out of your process, you'll have no idea which object was tapped in the Visual Intelligence, so your app won't have the context of the returned results.
This feature is built on top of existing system infrastructure — App Intents — where so long as there's that stable identifier, the system can come to your app's process, query for a specific recipe by ID through an EntityQuery
, and use that in concert with an OpenIntent
for this case. If your app adopts other significant system features that also use App Intents — Siri, Shortcuts, Spotlight, Widgets, and more — you'll find that these are the same code paths used in all those cases, where the system can query your app with an ID based on user interactions from outside of your process. Thus, you get to write your EntityQuery
once, and then get tons of value from across all those different features, without extra code.
Additionally, search results provided in IntentValueQuery come from network call. If we want to be able to search within these results in EntityQuery, does it mean we'll have to store a copy of these objects somewhere? It seems unsafe to do so, and there isn't a proper chance to remove them from storage when no longer needed.
Apps backed by large networked search results infrastructure have some specific decisions to make. If you have a data model object in your project that is very detailed with information containing far more than what you'd show in something like Visual Intelligence, you may want a separate AppEntity
structure that is only the relevant info shown throughout system experiences like Visual Intelligence. Our Trails sample code project demonstrates all of the core App Intents framework concepts, and one of the elements it takes care to do is separate a larger data model Trail
from the smaller AppEntity
version named TrailEntity
, in anticipation of needs like yours. There's a large code comment at the top of TrailEntity
that explains a bit more here. As to your statement there about storage, you'll have to determine a cache evection strategy as part of your app's data mangement that makes sense.
Looks like I can cheat EntityQuery.values(for:) by creating a new Entity with same id
Since your mentioning networked results above, the common strategy here is that you maintain the same ID for a data object all the way from your backend infrastructure into all the layers of your app including the AppEntity
, if that's feasible for how your data query and server search services are implemented.
— Ed Ford, DTS Engineer